Hello, I have a little messy code, so sorry about that (which is one of the reasons I am probably getting this bug)
Basically I made a script, attached it to gameobject, and it instantiates/spawns my prefab, but no matter what variable I put in InvokeRepeating in its function, I still get fixed instantiating, basically there are circles falling down in my game and I want to control how many circles spawn and how often etc. I managed to do this before but something went wrong in this particular script, here are notable spots in script:
in Start:
InvokeRepeating("SpawnCooldownChange", spawnCooldownFreq, spawnCooldownFreq); // No matter what I put here in variable, it does not actually change, even though in inspector it is changed
InvokeRepeating("SpawnObjectiveCircle", 0.1f, baseSpawnRepeat);
in void SpawnObjectiveCircle():
void SpawnObjectiveCircle()
{
GameObject newGameObject;
newGameObject = (GameObject)Instantiate(circles[Random.Range(0, 5)], defaultSpawn + new Vector3(0, 8, 0), transform.rotation);
newGameObject.transform.parent = this.transform;
list.Add(newGameObject);
GravityForce(); // give gravity
InvokeRepeating("DestroyOutOfView", 4, 3.0F);
...
in void DestroyOutOfView():
void DestroyOutOfView() //It basically despawns everything that leaves screen.
{
foreach (GameObject CirclesObject in list)
{
if (CirclesObject.gameObject.transform.position.y <= -8)
{
CirclesObject.gameObject.SetActive(false);
}
}
}
And this one is quite important one and probably cause of a bug, in void SpawnCooldownChange():
void SpawnCooldownChange()
{
if (baseSpawnRepeat > 2.7)
{
spawnCooldownFreq = 0.7f;
baseSpawnRepeat -= 0.08f;
}
else if (baseSpawnRepeat < 2.7 && baseSpawnRepeat > 1.6)
{
spawnCooldownFreq = 0.5f;
baseSpawnRepeat -= 0.16f;
}
else if (baseSpawnRepeat < 2.7 && baseSpawnRepeat > 0.7)
{
spawnCooldownFreq = 0.4f;
baseSpawnRepeat -= 0.18f;
}
else if (baseSpawnRepeat < 2.7 && baseSpawnRepeat > 0.25f) // FOR SOME REASON SAME ISSUE AGAIN, NO MATTER WHAT I GIVE, IT DOES 1 CIRCLE AT A TIME.
{
spawnCooldownFreq = 0.4f;
baseSpawnRepeat -= 0.16f;
}
}
^^ Here I just adjust how fast/often will they spawn
So problem is, it actually waits like 5 seconds and then instantiates instead of baseSpawnRepeat variable.
I posted this kinda in a hurry so please do tell me if I made any mistakes or forgot something.
I guess I did something really stupid so, help would be greatly appreciated!