Esempio n. 1
0
 private void Update()
 {
     //检测鼠标按下
     if (Input.GetMouseButtonDown(0))
     {
         //检测鼠标点击位置(按在UI的时候不做建造处理)
         if (EventSystem.current.IsPointerOverGameObject() == false)
         {
             //鼠标点转化为射线进行检测
             Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             //最大检测距离1000
             bool isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("TowerCube"));
             if (isCollider)
             {
                 //得到点击的cube
                 TowerCube cube = hit.collider.GetComponent <TowerCube>();
                 if (selectedTower != null && cube.TowerCubeOn == null)
                 {
                     if (money >= selectedTower.cost)
                     {
                         //建塔
                         MoneyUpdate(selectedTower.cost);
                         moneyreduce.SetTrigger("test");
                         cube.BuildTower(selectedTower);
                     }
                     else
                     {
                         //钱不够
                         moneyreduce.SetTrigger("nomoney");
                     }
                 }
                 //有炮塔   做升级或拆迁处理
                 else if (cube.TowerCubeOn != null)
                 {
                     //是否选中同一炮塔并且画布是否被使用
                     if (cube == SelectedTowerObject && UpgradeCanves.activeInHierarchy)
                     {
                         HideUpgradeUI();
                     }
                     else
                     {
                         ShowUpgradeUI(cube.transform.position, cube.isUpgrade);
                     }
                     SelectedTowerObject = cube;
                 }
             }
         }
     }
 }