- Home /
Question by
JusttSomeone · Jan 04, 2021 at 10:18 PM ·
scripting problemscripting beginnerbeginner
Issue with spawn timing getting delayed,Issue with timing of BlockSpawner
I'm starting now in Unity and I'm making a rhythmic vertical dodge the blocks game, I'm having an issue where, as a rhythmic game, the blocks must be spawning precisely with the beat timing, but it's spawning more and more delayed over the waves, I don't know what to do, please help me. I just want to set perfectly the spawn time and the time between the waves.
using UnityEngine;
public class BlockSpawner : MonoBehaviour
{
public Transform[] spawnPoints;
public GameObject blockPrefab;
public float timeBetweenWaves = 4.068f;
public float timeToSpawn = 1.525f;
void Update()
{
if (Time.time >= timeToSpawn)
{
SpawnBlocks();
timeToSpawn = Time.time + timeBetweenWaves;
}
}
void SpawnBlocks()
{
int randomIndex = Random.Range(0, spawnPoints.Length);
for (int i = 0; i < spawnPoints.Length; i++)
{
if (randomIndex != i)
{
Instantiate(blockPrefab, spawnPoints[i].position, Quaternion.identity);
}
}
}
}
Comment