コード例 #1
0
        public void towerSpawn()
        {
            Enemy[] enemies = FindObjectsOfType <Enemy>();
            foreach (Enemy enemy in enemies)
            {
                if (gameObject.GetComponent <Collider>().bounds
                    .Intersects(enemy.gameObject.GetComponent <Collider>().bounds))
                {
                    return;
                }
            }

            Vector3 pos = gameObject.transform.position;

            pos.y = pos.y + 0.7f;
            if (gManager.Gold >= 10 && !_hasTower)
            {
                gManager.SpendGold(10);
                GameObject tower = Instantiate(Resources.Load("Tower"), pos, new Quaternion(0, 0, 0, 0), gameObject.transform.parent) as GameObject;
                tower.transform.parent = gameObject.transform;
                _hasTower         = true;
                gManager.LastCell = this.gameObject;
                gManager.menuOpen = false;
                bMenu.SetActive(false);
            }
            else if (gManager.Gold < 10)
            {
                StartCoroutine(noMoney());
            }
            else
            {
                StartCoroutine(isBuilt());
            }
        }