Exemple #1
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (EventSystem.current.IsPointerOverGameObject() == false)
         {
             Ray        ray = MainCam.GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
             if (isCollider)
             {
                 Cube mapCube = hit.collider.GetComponent <Cube>();
                 if (selectedTurretData != null && mapCube.turretGo == null && MainCam.activeSelf == true)
                 {
                     Debug.Log("Try to build");
                     if (money >= selectedTurretData.cost)
                     {
                         UpdateMoney(-selectedTurretData.cost);
                         mapCube.BuildTurret(selectedTurretData.turretPrefab);
                     }
                     else
                     {
                         moneyAnimator.SetTrigger("money");
                     }
                 }
                 else if (mapCube.turretGo != null)
                 {
                     MainCam.SetActive(false);
                     GameObject new_view = mapCube.turretGo.transform.GetChild(0).gameObject;
                     new_view.SetActive(true);
                 }
             }
         }
     }
 }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (EventSystem.current.IsPointerOverGameObject() == false)
            {
                //开发炮台的建造
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("Cube"));
                if (isCollider)
                {
                    Cube cube = hit.collider.GetComponent <Cube>();

                    if (selectedTData != null && cube.turretGo == null)
                    {
                        //可以创建
                        if (gameManager.money > selectedTData.cost)
                        {
                            gameManager.ChangeMoney(-selectedTData.cost);
                            cube.BuildTurret(selectedTData);
                        }
                        else
                        {
                            //提示钱不够
                            moneyAnimator.SetTrigger("Flicker");
                        }
                    }
                    else if (cube.turretGo != null)
                    {
                        // 升级处理

                        //if (mapCube.isUpgraded)
                        //{
                        //    ShowUpgradeUI(mapCube.transform.position, true);
                        //}
                        //else
                        //{
                        //    ShowUpgradeUI(mapCube.transform.position, false);
                        //}
                        if (cube == selectedCube && upgradeCanvas.activeInHierarchy)
                        {
                            StartCoroutine(HideUpgradeUI());
                        }
                        else
                        {
                            ShowUpgradeUI(cube.transform.position, cube.isUpgraded);
                        }
                        selectedCube = cube;
                    }
                }
            }
        }
    }