Esempio n. 1
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (EventSystem.current.IsPointerOverGameObject() == false)
         {
             // not on UI
             Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             bool       isCollided = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
             if (isCollided)
             {
                 MapCube mapCube = hit.collider.GetComponent <MapCube> ();
                 if (selectedTurret != null && mapCube.currentTurret == null)
                 {
                     //can build
                     if (money > selectedTurret.cost)
                     {
                         ChangeMoney(-selectedTurret.cost);
                         if (selectedTurret.turretPrefab != null)
                         {
                             mapCube.CreateTurret(selectedTurret);
                         }
                     }
                     else
                     {
                         //money is not enoungh
                         moneyAnim.SetTrigger("flash");
                     }
                 }
                 else if (mapCube.currentTurret != null)
                 {
                     //turret update
                     if (mapCube == selectedMapcubeInScene && updCanvas.activeInHierarchy)
                     {
                         //The Same Turret click twice && UI is Showed
                         HideUpdUI();
                     }
                     else
                     {
                         ShowUpdUI(mapCube.transform.position, mapCube.isUpded);
                     }
                     selectedMapcubeInScene = mapCube;
                 }
             }
         }
     }
 }
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (EventSystem.current.IsPointerOverGameObject() == false)
         {
             Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             if (Physics.Raycast(ray, out hit, 100, LayerMask.GetMask("MapCube")))
             {
                 mapCube = hit.collider.GetComponent <MapCube>();
                 if (mapCube.transform.childCount <= 0 && selectedTurret != null)
                 {
                     if (currentMoney >= selectedTurret.normalCost)
                     {
                         ChangeMoney(selectedTurret.normalCost);
                         mapCube.CreateTurret(selectedTurret, hit.collider.transform);
                     }
                     else
                     {
                         ShowCoinText();
                     }
                 }
                 else if (mapCube.transform.childCount > 0 && mapCube.currentTurret.turretType == selectedTurret.turretType)
                 {
                     if (currentMoney >= selectedTurret.upgradeCost)
                     {
                         isSameMapCube = mapCube;
                     }
                     else
                     {
                         ShowCoinText();
                     }
                 }
             }
         }
     }
 }