I want to spawn an object every 0.5 sec, but when the program starts it spawn everything at the same time.
void Start()
{
for (int i = 0; i < 20; i++)
{
SpawPiattaforma();
}
}
// Update is called once per frame
void Update()
{
if (gameOver)
CancelInvoke("SpawPiattaforma");
if (MovimentoPalla.current.partito)
InvokeRepeating("SpawPiattaforma", 1, 0.5f);
}
You call another InvokeRepeating every frame. Thus, 60 times pers second you ask unity to start spawning object every 0,5 seconds. Of course it spawning all the time. Call it once.
What @palex-nx said is really the only reliable way to do it position or distance.
In my game (check sig, its a really crappy game btw.) I base spawning off of distance between to make sure its timed just right, or appears that way as its not based on time. That way I can change the distance and speed on the fly and everything works out(hopefully.)
The camera doesn’t move, so everything is moving from right to left. Distance is like position in this scenario. As the game progresses the speed increases and the distance between “toilets” decreases, increasing difficulty. The distance is random based on the difficulty as it increase with the passing of time.