void Start() { owningPlayer = GetComponentInParent <Commander> (); ConstructEffect = Instantiate(ConstructEffect, this.transform); startBuilding(); //when created, building starts constructing first (so that it sinks to the ground first) if (BuildingMenu) //if building has a menu { BuildingMenu = Instantiate(BuildingMenu) as GameObject; BuildingMenu.GetComponent <Canvas>().enabled = false; //is hidden initialy BuildingMenu.transform.SetParent(this.gameObject.transform, false); Vector3 menuPos = new Vector3(0f, 11f, 0f); BuildingMenu.transform.SetPositionAndRotation(gameObject.transform.position + menuPos, gameObject.transform.rotation); BuildingMenuController thisBuildingMenuController = BuildingMenu.GetComponentInChildren <BuildingMenuController> (); thisBuildingMenuController.createMenu(objectsCanSpawn); } }
// FIXME: Becoming way too big, refactor. void OldStart() { unitsList = new List <GameObject> (); spawnersList = new List <Spawn> (); towersList = new List <TowerController> (); //Get spawners list GameObject[] spawners = GameObject.FindGameObjectsWithTag("Spawner"); foreach (GameObject spawner in spawners) { Spawn newSpawn = spawner.GetComponent <Spawn> (); if (newSpawn != null) { spawnersList.Add(newSpawn); newSpawn.OnSpawn += OnUnitSpawn; } } if (spawnersList.Count == 0) { Debug.LogWarning("GameController :: Start - No spawners found."); } //Get towers list GameObject[] towers = GameObject.FindGameObjectsWithTag("Tower"); foreach (GameObject tower in towers) { TowerController newTower = tower.GetComponent <TowerController> (); if (newTower != null) { towersList.Add(newTower); newTower.onTowerClicked += OnTowerClicked; } } if (spawnersList.Count == 0) { Debug.LogWarning("GameController :: Start - No towers found."); } // Get buildingMenuController // TODO: Make buildingMenuController singleton. GameObject buildingMenuGO = BuildingMenuController.Instance.gameObject; if (buildingMenuGO == null) { Debug.LogError(gameObject.name + " :: Start - Could not find Building Menu"); } else { buildingMenuController = buildingMenuGO.GetComponent <BuildingMenuController> (); if (buildingMenuController == null) { Debug.LogError(gameObject.name + " :: Start - " + buildingMenuGO.name + " does not have BuildingMenuController component attached"); } else { foreach (TowerController towerController in towersList) { towerController.onTowerSelected += buildingMenuController.OnTowerSelected; } } } // Get mouseController mouseController = FindObjectOfType <MouseController>(); if (mouseController == null) { Debug.LogError(gameObject.name + " :: Start - Could not find Mouse Controller component."); } else { mouseController.unselectEverything += buildingMenuController.HideMenu; } }