Spawn Objects After Different Time Intervals
Hi need help ... I made 4 game objects in my game instantiated them form 4 sides of the screen. It works fine but now i want these game objects to be spawned at different time intervals and with the passage of time the time decreases and objects spawn increase. I am using c# and cant find any way to get out of it .... Please help
Answer by Shoon · Sep 12, 2015 at 01:51 PM
I won't really write you any code, but I'm giving you an approach.
First you have to think what matters in your code, what variables will you need. In this case you will need a starting spawn interval (the first amount of time before the first 4 gameobjects are instantiated) and the amount of gameobjects to be spawn (could be 4 initially in this case). So let's say:
float spawnInterval = 2.0f;
int numberToSpawn = 4;
Then all is around time. The easiest way to check how many time have passed from the last spawn is to create another variable and equals it to the actual time when you first spawn your gameobjects. You can get that time with
Time.time;
Then inside the Update() function you can check for difference between the actual time (Time.time again) and last time you spawned your gameobjects. If that is equals or bigger than your spawnInterval value, then you can call a function to instantiate your gameobjects. After that, you must gradually decrease the spawnInterval and increase the number of gameobjects to spawn (you can do this in whatever relation, just start with some random relationship and by playtesting adjust it).
Hope it will help !
Answer by waha_ali · Sep 14, 2015 at 05:30 AM
I tried this but i cant get required result Even assigning and selecting a random number of these object just spawn the first game object it finds I want then ti spawn randomly from any of the four objects
Your answer
Follow this Question
Related Questions
Spawning random objects not working 2 Answers
Player spawn in the center of the world 2 Answers
How to drop a box 0 Answers
error CS1526: A new expression requires () or [] after type 1 Answer
[uNET] Network objects spawned not spawn in new clients 1 Answer