Esempio n. 1
0
    public void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            //当UI和Cube不重合时,进行建造
            if (EventSystem.current.IsPointerOverGameObject() == false)
            {
                //开发炮台的建造
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                bool       isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapCube"));
                if (isCollider)
                {
                    MapCube mapCube = hit.collider.GetComponent <MapCube>();
                    //判断cube身上有没有炮台
                    if (selectedPaoTai != null && mapCube.PaoTai == null)
                    {
                        //可以创建
                        if (money >= selectedPaoTai.cost)
                        {
                            ChangeMoney(-selectedPaoTai.cost);
                            mapCube.BuildPaoTai(selectedPaoTai);
                        }
                        else //提示钱不够
                        {
                            moneyAnimator.SetTrigger("ShanShuo");
                        }
                    }
                    //升级处理
                    else if (mapCube.PaoTai != null)
                    {
                        //show(mapCube.transform.position, mapCube.isUpgraded);

                        //表示升级UI是否显示出来
                        if (mapCube == selectedMapCube && SJCanvas.activeInHierarchy)
                        {
                            Hide();
                        }
                        else
                        {
                            show(mapCube.transform.position, mapCube.isUpgraded);
                        }
                        selectedMapCube = mapCube;
                    }
                    //GameObject mapCube = hit.collider.gameObject;//得到点击的Cube
                    //if()
                }
            }
        }
    }