void ShowTowerInformation()
    {//顯示點選的塔的資訊
        if (targetTower == null)
        {
            return;
        }

        towerInformation.transform.position = Camera.main.WorldToScreenPoint(MousePositionInWorld.MousePosition());

        RenewTowerInformation();
        towerInformation.SetActive(true);
    }
    public void BuildTower()
    {
        //扣除掉建塔需要消耗的錢
        gameManager.GetComponent <GameManager>().CostMoney(-willBuildingTower.GetComponent <Tower>().costMoney);
        willBuildingTower.transform.position = MousePositionInWorld.MousePosition();
        //  willBuildingTower.SetActive(false);
        //  GameObject newTower = Instantiate(willBuildingTower, willBuildingTower.transform.position, willBuildingTower.transform.rotation);
        gameManager.GetComponent <TowerManager>().BuildTowerInMap(willBuildingTower);

        //    Destroy(willBuildingTower);
        willBuildingTower = null;
        nowBuilding       = false;
    }
    public void ClickToSelectTower()
    {//點選塔,如果塔的資訊還在顯示的話就不執行
        if (towerInformation.activeInHierarchy)
        {
            return;
        }

        Collider2D towerCollider = Physics2D.OverlapPoint(MousePositionInWorld.MousePosition(), 1 << LayerMask.NameToLayer("TowerBase"));

        if (towerCollider != null)
        {
            targetTower = towerCollider.transform.parent.gameObject;
            ShowTowerInformation();
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Time.timeScale == 0)
        {
            return;
        }

        if (!nowBuilding)
        {
            return;
        }
        if (Input.GetMouseButtonDown(1))
        {
            CancelBuild();//取消建造
            return;
        }

        Vector3 mouseInWhere = MousePositionInWorld.MousePosition();

        willBuildingTower.transform.position = mouseInWhere;//取得游標座標
        //判斷游標目前座標是否有跟Collider2D重疊
        Collider2D[] allCollider = Physics2D.OverlapPointAll(mouseInWhere);
        willBuildingTower.GetComponent <DrawTowerRange>().DrawRange(); //畫出射程範圍

        if (allCollider.Length == 0)                                   //為0 代表目前位置沒有任何塔或可建造區域 因此不做後續判斷
        {
            return;
        }
        bool canBuild = false;

        foreach (var r in allCollider)
        {//取出重疊的Collider2D
            if (r != null)
            {
                if (r.tag == "BuildArea" && willBuildingTower.transform.Find("BuildBase").GetComponent <TowerBuilding>().overlapCount == 0)
                {//游標的的位置位於BuildArea中,並且重疊到的塔的數量為0
                    canBuild = true;
                    break;
                }
            }
        }
        if (canBuild)//依據可否建造改變顏色
        {
            willBuildingTower.transform.Find("BuildBase").GetComponent <TowerBuilding>().CanBuildToSetColor();
        }
        else
        {
            willBuildingTower.transform.Find("BuildBase").GetComponent <TowerBuilding>().CanNotBuildToSetColor();
        }


        if (Input.GetMouseButtonDown(0))
        {
            if (canBuild)
            {
                BuildTower();
            }
            else
            {
                Debug.Log("can't build");
            }
        }
    }