using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Buid : MonoBehaviour
{
    public GameObject standardPre;
    public GameObject missilePre;
    public GameObject laserPre;
    GameObject curTower;
    void Start()
    {
        curTower = standardPre;
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            bool isHit = Physics.Raycast(ray, out hit, 500, LayerMask.GetMask("base"));
            if (isHit)
            {
                GameObject obj = hit.collider.gameObject;
                if (obj.transform.childCount == 0)
                {
                    GameObject tar = Instantiate(curTower, obj.transform.position, Quaternion.identity);
                    tar.transform.parent = obj.transform;
                }
            }
        }
    }
    public void selStandard(bool isOn)
    {
        if (isOn)
        {
            curTower = standardPre;
        }
    }
    public void selMissile(bool isOn)
    {
        if (isOn)
        {
            curTower = missilePre;
        }
    }
    public void selLaser(bool isOn)
    {
        if (isOn)
        {
            curTower = laserPre;
        }
    }
}
