public void FindNearestTower() { structuresPool = GameObject.FindGameObjectsWithTag("Structure"); int numOfStructures = structuresPool.Length; //Debug.Log(numOfStructures); float closestDist = 999999; for (int i = 0; i < numOfStructures; i++) { GameObject structure = structuresPool[i]; if (!structure.activeInHierarchy || !structure.GetComponent <StructureBase>().isActive) { continue; } Vector3 dist2Structure = structure.transform.position - transform.position; float magSquared = dist2Structure.sqrMagnitude; if (magSquared < closestDist || i == 0) { closestDist = magSquared; //closestTarget = structure; closestTarget = structure.GetComponent <StructureBase>(); } } }
private void OnTriggerEnter(Collider other) { StructureBase structure = other.GetComponent <StructureBase>(); if (structure != null && structure == parent.closestTarget) { parent.hasReachedTarget = true; parent.newTarget = false; } }
public void LoadTorrentArcStructure() { GameObject child = GetInactiveChild(torrentArcPool); if (child != null) { structureToPlace = child.GetComponent <StructureBase>(); structureToPlace.isActive = false; groundManager.TurnOnTiles(structureToPlace.borderList); } }
void PlaceStructure(TileScript tile) { if (currentMoney >= structureToPlace.cost) { structureToPlace.isActive = true; currentMoney -= structureToPlace.cost; moneyText.text = "" + currentMoney; structureToPlace.ResetStructure(); structureToPlace.Build(); structureToPlace = null; groundManager.SetTileSpace(tile); groundManager.TurnOffTiles(); } else { Debug.Log("Not Enough Money" + currentMoney + "/" + structureToPlace.cost); } }
void Awake() { parent = transform.parent.GetComponent <StructureBase>(); gameObjectList = new List <GameObject> (); }