c# - Enemies All Spawning In Same Place -


i want enemies spawn in 4 different locations survival-type game. problem is, spawn in same place. why this? in unity way.

c# script:

using system.collections; using system.collections.generic; using unityengine;  public class spawner : monobehaviour { public int spawnhere = 0; public int spawntimer = 0; public int spawnrate = 1; public transform spawner1; public transform spawner2;  public transform spawner3; public transform spawner4; public gameobject melee1;   // use initialization void start () {    }  // update called once per frame void update () {     spawntimer = spawntimer + spawnrate;     spawnhere = random.range (1, 5);     if(spawntimer >= 120) {         if(spawnhere == 1) {             instantiate (melee1, spawner1); }         if(spawnhere == 2) {             instantiate (melee1, spawner2);         }         if(spawnhere == 3) {             instantiate (melee1, spawner3);         }         if(spawnhere == 4) {             instantiate (melee1, spawner3);         }         spawntimer = 0;    }  } } 

have connected spawners correctly in ui?

watch this: unity - survival shooter - spawning enemies

this worked pretty project.

you should use time.deltatime timing spawns. not every system outputs same amount of frames / second.

unity - docs - time.deltatime

btw:

random.rand(min, max)

unity - docs - random.rand includes max possible value.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -