I have a Porblem. I try to recreate the 2D roghlike game. My Enemys and the Player arent moving. The Problem is in the Coroutine. The Log1 is Displayed, but Log 2 isnt. Code: Code (CSharp): void Update() { if (playersTurn || enemiesMoving) return; StartCoroutine(MoveEnemies()); Debug.Log("Log1"); } IEnumerator MoveEnemies() { enemiesMoving = true; yield return new WaitForSeconds(turnDelay); if (enemies.Count == 0) { yield return new WaitForSeconds(turnDelay); } for (int i = 0; i < enemies.Count; i++) { enemies[i].MoveEnemy(); Debug.Log("2"); yield return new WaitForSeconds(enemies[i].moveTime); } playersTurn = true; enemiesMoving = false; } public void MoveEnemy() { int xDir = 0; int yDir = 0; if (Mathf.Abs(target.position.x - transform.position.x) < float.Epsilon) yDir = target.position.y > transform.position.y ? 1 : -1; else xDir = target.position.x > transform.position.x ? 1 : -1; AttemptMove<Player>(xDir, yDir); }
It doesnt start when Enemiesmoving = true. And at the start of the Coroutine, its set to true and at the end to false. Shouldnt this work?