Ok this may be a little bit long winded so be patient.
I am trying to get a list of all my enemies on my game manager script, then on that same script start a coroutine to loop through each enemy and start a coroutine on the enemy for it to execute its turn. I THINK I have most of it figured out in terms of using bools to wait for the first enemy to finish its turn before iterating to the next enemy and letting that one start its turn. The issue I am having is that in the game manage script I am getting an error and it is not letting me call the coroutine from the enemy script. it will let me call other functions from the enemy script like TakeDamage(); for example, but not start the coroutine.
If you guys could shed some light on this for me that would be greatly appreciated.
// EnemyScript and the coroutine on it that I am trying to run
public IEnumerator EnemyTurn()
{
if (gm.battleState != BattleState.ENEMYTURN)
{
yield break;
}
Vector3 target = new Vector3(targetPlayer.position.x, targetPlayer.position.y - 0.5f, 0f);
Vector3 startCellPos = grid.WorldToCell(target);
Vector3Int startCellPosInt = Vector3Int.FloorToInt(startCellPos);
Vector3 endScreenPos = grid.CellToWorld(startCellPosInt);
Vector3 destination = new Vector3(endScreenPos.x, endScreenPos.y + 0.5f, 0f);
while (transform.position != destination)
{
transform.position = Vector3.MoveTowards(transform.position, destination, moveSpeed * Time.deltaTime);
yield return null;
}
yield return new WaitForSeconds(1.5f);
gm.enemyTurnCompleted = true;
yield break;
}
// GameManager here is the gm script with the relevant areas
IEnumerator EnemyTurnRoutine()
{
if (enemies.Length == 0)
{
CheckAllEnemiesDead();
battleState = BattleState.WON;
EndLevel();
yield break;
}
for (int i = 0; i < enemies.Length; i++)
{
enemyTurnCompleted = false;
enemies[i].StartCoroutine(EnemyTurn());
yield return new WaitUntil(() => enemyTurnCompleted == true);
}
yield return new WaitForSeconds(1);
CheckEndOfTurn();
enemyTurnStarted = false;
yield break;
}
I activate the EnemyTurnRoutine in the update method of the gm script. Also like I said previously if I try to change the line..
enemies[i].StartCoroutine(EnemyTurn());
with something like
enemies[i].TakeDamage(int);
it works perfectly fine. The intelesense picks it up and everything is happy. But when I try to start coroutine the intelesense does not offer the EnemyTurn coroutine at all, and when I put it in manually it says "The name 'EnemyTurn' does not exist in the current context"
Any and all help would be appreciated!
↧