List <GameObject> GetTowersAtPosition(Vector3 positionWorld) { List <GameObject> hits = new List <GameObject>(); GameObject[] towers = GameObject.FindGameObjectsWithTag("Tower"); foreach (GameObject tower in towers) { BoxCollider2D collider = tower.GetComponent <BoxCollider2D>(); if (collider.OverlapPoint(positionWorld)) { TowerCanBeLiftedBehavior canBeLiftedBehavior = tower.GetComponent <TowerCanBeLiftedBehavior>(); if (canBeLiftedBehavior != null && canBeLiftedBehavior.enabled) { GameObject tempTower = tower; while (tempTower.transform.parent != null) { tempTower = tempTower.transform.parent.gameObject; } hits.Add(tempTower); } } } return(hits); }
public TowerBehavior() { OnPlaced += (towerRoot) => { TowerCanBeLiftedBehavior canBeLiftedBehavior = towerRoot.GetComponentInChildren <TowerCanBeLiftedBehavior>(); canBeLiftedBehavior.enabled = false; shootObjectDetection.enabled = true; towerShopUiParent.SetActive(false); }; }