Hello I really caught interest in game development a few weeks ago and I’m making a recreation of a mobile game called Super Hexagon and I have a problem that I think is caused by a obstacle spawning script that makes it so when I when I start the game it spawns 2 hexagons placed in each other so it’s almost impossible to get past them (everything else is working correctly) I think that this script is causing the problem
using UnityEngine;
public class Spawner : MonoBehaviour {
public float spawnRate = 1f;
public GameObject hexagonPrefab;
private float nextTimeToSpawn = 0.5f;
void Update()
{
if (Time.time >= nextTimeToSpawn)
{
Instantiate(hexagonPrefab, Vector3.zero, Quaternion.identity);
nextTimeToSpawn = Time.time + 1f / spawnRate;
}
}
}
Iarus
2
What is the value of Time.time when the game starts?
public float firstTimeToSpawn = 0.5f;
private float nextTimeToSpawn;
void Start()
{
nextTimeToSpawn = Time.time + firstTimeToSpawn;
}
//everything else stays the same.
I think Time.time is equal to 0 the moment the game starts, by “the game starts” I mean the application is launched. Time.time is not specific to the lifetime of a scene or GameObject and is not reset to zero when you load a scene.