IEnumerator Coordinator() { float xMin = map.GetComponent <BoxCollider>().bounds.min.x + 2f; float xMax = map.GetComponent <BoxCollider>().bounds.max.x - 2f; float zMin = map.GetComponent <BoxCollider>().bounds.min.z + 2f; float zMax = map.GetComponent <BoxCollider>().bounds.max.z - 2f; while (true) { var target = PositionOnMap.Pick(xMin, xMax, zMin, zMax); StartCoroutine(RotateToTarget(target - transform.position)); while (!IsCloseToTarget(target)) { if (IsCloseToBorder(xMin, xMax, zMin, zMax)) { target = PositionOnMap.Pick(xMin, xMax, zMin, zMax); StartCoroutine(RotateToTarget(target - transform.position)); yield return(new WaitForSeconds(2f)); break; } yield return(new WaitForSeconds(0.02f)); } } }
IEnumerator SpawnTank() { float xMin = map.GetComponent <BoxCollider>().bounds.min.x + 2f; float xMax = map.GetComponent <BoxCollider>().bounds.max.x - 2f; float zMin = map.GetComponent <BoxCollider>().bounds.min.z + 2f; float zMax = map.GetComponent <BoxCollider>().bounds.max.z - 2f; yield return(new WaitForSeconds(1)); while (true) { var tankInst = Instantiate(tankPrefab); tankInst.GetComponent <TankMovement>().Init(map); tankInst.transform.position = PositionOnMap.Pick(xMin, xMax, zMin, zMax); yield return(new WaitForSeconds(SPAWN_DELAY)); } }