In my game random objects are created at screen in certain times, and the player should collect then, after collecting 10 of then, the time scale should go to 2f to make then fall faster and spawn faster too but i’ve tryed a lot of different things and nothing works. How could i do it?
Here is my code:
public GameObject prefab;
public float spawnTime = 2f;
private float timer;
private int counter = 0;
void Update()
{
if (counter > 10)
{
Time.timeScale = 2f;
}
timer += Time.deltaTime;
if (timer > spawnTime)
{
Vector2 position = new Vector2(Random.Range(-2.6f, 2.6f), 5f);
Instantiate(prefab, position, Quaternion.identity);
timer = 0;
counter += 1;
}
}