public IEnumerator coBuilder() { if (Physics.BoxCast(activeCell.transform.position, new Vector3(0.5f, 0.1f, 0.5f), Vector3.up, Quaternion.identity, 1.0f)) { buildMenu.transform.Find("warningText").GetComponent <Text>().text = "enemies in cell."; yield break; } GameObject testTower = Instantiate(Globals.gm.tower, new Vector3(activeCell.transform.position.x, 0.59f, activeCell.transform.position.z), activeCell.transform.rotation); testTower.GetComponent <MeshRenderer>().enabled = false; testTower.transform.GetChild(0).GetComponent <MeshRenderer>().enabled = false; GameObject testEnemy = (GameObject)Object.Instantiate(simpleEnemy, Globals.em.transform.position, Globals.em.transform.rotation); testEnemy.GetComponent <MeshRenderer>().enabled = false; yield return(null); if (testEnemy.GetComponent <NavMeshAgent>().pathStatus != NavMeshPathStatus.PathComplete) { buildMenu.transform.Find("warningText").GetComponent <Text>().text = "blocks path"; Destroy(testTower); Destroy(testEnemy); yield break; } foreach (NavMeshAgent jBond in Globals.em.GetComponentsInChildren <NavMeshAgent>()) { if (jBond.pathStatus != NavMeshPathStatus.PathComplete) { buildMenu.transform.Find("warningText").GetComponent <Text>().text = "blocks path"; Destroy(testTower); Destroy(testEnemy); yield break; } } Destroy(testTower); Destroy(testEnemy); buildMenu.transform.Find("warningText").GetComponent <Text>().text = ""; buildMenu.active = false; Globals.pm.AddMoney(-towerCost); activeCell.BuildTower(); activeCell = null; }