- Home /
Question by
mert-erdem · Oct 21, 2020 at 10:58 PM ·
3dspawningspawning problemszombiespawning-enemies
Problem with the randomly spawning enemies
Only the latest zombie is responsive to player movement and shooting. When I kill a zombie, the last zombie is dying. Also when I approach another zombie(not the last one), it is not attacking. I think the problem is not in the script.
The zombie spawning script ;
private int delay=2;
public GameObject zombie;
private Vector3 newPosition;
void Update()
{
if(delay<Time.timeSinceLevelLoad)
{
newPosition = new Vector3(-15.03345f, 2.287f, Random.Range(-5f, 8f));
Instantiate(zombie, newPosition,
Quaternion.Euler(zombie.transform.rotation.x, zombie.transform.rotation.y, zombie.transform.rotation.z));
delay+=5;
}
}
Comment
I used "this" keyword before transform for several code lines. Such as; anim = this.transform.GetComponent();
This solved the problem that I asked.
Your answer
Follow this Question
Related Questions
How to spawn enemies at different locations and avoid overlapping each other 2 Answers
Respawn script not working! 0 Answers
How to spawn all humans at once and activate then with time? 1 Answer
[Help] How Do I Randomly Spawn Game Objects On Specific Coordinates? 3 Answers
Question about Unet and spawning 0 Answers