Hello everyone, I hope you are doing well.
Actually the code below is same as it is in the course but still output is very different, it is the EnemySpawner script of the game Realm Rush, in which we instantiate multiple enemies after a particular interval of time.
public class EnemySpawner : MonoBehaviour
{
[Range(0.1f, 120f)]
[SerializeField] float secondsBetweenSpawns = 2f;
[SerializeField] EnemyMovement enemyPrefab;
void Start()
{
StartCoroutine(RepeatedlySpawnEnemies());
}
IEnumerator RepeatedlySpawnEnemies()
{
while (true) // forever
{
print("Spawning");
Instantiate(enemyPrefab, transform.position, Quaternion.identity);
yield return new WaitForSeconds(secondsBetweenSpawns);
}
}
}
And after playing it in unity what it does is very different and unexpected it makes multiple clones of the game object. I have attached a Screenshot of the output.
As you can see that there are many clones of the ‘Enemy’ game object so please explain me that why is this happening and what can I dot to solve this problem.