I'm making a small game similar to Super Hexagon. I've recently asked a question about making the game harder as the player progresses by increasing the obstacles' spawn rate. I was able to implement this feature with the help of an answer. The game works fine in the game view and the spawn rate is low at first and increases slowly which is exactly what I want. But the problem starts where I create a build. Unlike the game view, the spawn rate is high as soon as the game starts but after a few seconds it changes back to what it was in the game view. I changed the values on the Animation Curve multiple times and found out that this difference only occurs with my current values. In fact, if I change the values to something that starts high at the beginning, the game view and the build behave similarly but using values like these and even smaller, creates this issue.
Spawner script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour
{
// the spawn rate is 1 in the inspector and it doesn't change by the curve.
public float spawnRate = 1f;
public GameObject hexagonPrefab;
private float nextTimeToSpawn = 0f;
public AnimationCurve spawnOverTime;
public LifeTime life;
void FixedUpdate()
{
float spawn = spawnRate * spawnOverTime.Evaluate(life.TimeAlive);
if (Time.time >= nextTimeToSpawn)
{
Instantiate(hexagonPrefab, Vector3.zero, Quaternion.identity);
nextTimeToSpawn = Time.time + spawn / spawnRate;
}
}
}
The game when it starts in the game view.
The game when the build starts.
This is the spawner's Animation Curve.
First point from left: time = 11, value = 1
Second point: time = 164.2441 , value = 0.3
Start()
method withnextTimeToSpawn = Time.time;
? \$\endgroup\$Start()
method solved the problem. Thank you very much! I don't think this matters now but no, I don't have another scene before this one. I'll write the new code as an answer just in case if somebody else has the same problem. \$\endgroup\$