- Home /
How to spawn all humans at once and activate then with time?
What I am trying to do is to spawn humans that will simply pass by my charactarter, I have wrote a script However constant spawning causes some flickering in Oculus, thus I want to redo it the way that all humans will be spawned at once and activated with time, but I am worried that humans will overlap each other and it will cause problems. Will be thankful if you could recommend me an elegant way to solve this problem.
void Spawn()
{
Debug.Log("Spawn Function Activated");
RandomHuman = Random.Range(0, humans.Length);
GameObject spawnedPrefab = Instantiate(humans[RandomHuman], new Vector3(transform.position.x, 0, transform.position.z), transform.rotation);
}
void Start()
{
InvokeRepeating("Spawn", 0f, 3f);
}
void Update()
{
SpawnWait = Random.Range(SpawnLeastWait, SpawnMostWait);
}
Answer by xxmariofer · Jan 22, 2019 at 11:09 AM
They are just static objects that dont move? the best way of doing this is spawning a pool of objects at the start in awake or something like that and change the spawn method to rpositionate, and rather than instantiate the object just positionate one of the objects of the pool in the desired position
No, that 's the problem, they are not static and have and animation script attached .
Then just spawn them at the start and use the GameObject.SetActive() method, just repositionate and reactivate them, i would suggest checking a tutorial of object pooling if its your first time doing this.
Your answer
Follow this Question
Related Questions
How to spawn enemies at different locations and avoid overlapping each other 2 Answers
How to prevent multiple spawns from a single spawn point? 1 Answer
How to increase the spawn rate of an object over time? 2 Answers
SPAWNING ENEMIES and controlling the amount/interval 1 Answer
Spawning help 1 Answer