- Home /
Why is my game not exporting correctly?
So I'm making a game where i have a spawner that only spawns certain prefabs, until a certain amount of time has passed. There are two times where it starts spawning more types of prefabs. Once after 5 seconds, and then when 30 seconds has passed, It unlocks even more things to be spawned. This works fine in the editor...but...when i export the game it doesn't work. When the 5 seconds pass, the new prefabs are spawned, but after 30 seconds...nothing. It just stays like it is. This is really annoying, cause i really need this to work, since these prefabs add a lot of variation to my game. (Don't want to give too many details)
So the way i actully do this is(example):
public GameObject prefab1;
public GameObject prefab2;
public GameObject prefab3;
public GameObject prefab4;
public GameObject prefab5;
public float rate = 2f;
public float nextSpawn = 0f;
public int whatToSpawn;
public float narrowTime = 30f;
public float movingTime = 5f;
void Update()
{
if (Time.time >= nextSpawn)
{
if (Time.time >= narrowTime)
{
whatToSpawn = Random.Range(1, 6);
switch (whatToSpawn)
{
case 1:
Instantiate(prefab1, Transform.position, Quaternion.identity);
break;
case 2:
Instantiate(prefab2, Transform.position, Quaternion.identity);
break;
case 3:
Instantiate(prefab3, Transform.position, Quaternion.identity);
break;
case 4:
Instantiate(prefab4, Transform.positon, Quaternion.identity);
break;
case 5:
Instantiate(prefab5, Transform.position, Quaternion.Identity);
break;
}
}
else if (Time.time >= movingTime)
{
whatToSpawn = Random.Range(1, 4);
switch (whatToSpawn)
{
case 1:
Instantiate(prefab1, Transform.position, Quaternion.identity);
break;
case 2:
Intsantiate(prefab2, Transform.position, Quaternion.identity);
break;
case 3:
Instantiate(prefab3, Tranform.position, Quaternion.identity);
break;
}
}
else
{
whatToSpawn = Random.Range(1, 3);
switch (whatToSpawn)
{
case 1:
Instantiate(prefab1, Transform.position, Quaternion.identity);
break;
case 2:
Instantiate(prefab2, Transform.position, Quaternion.identity);
break;
}
}
nextSpawn = Time.time + rate;
}
}
So basically i have a variable with the value of 5, and one with 30. I check if the in game time has reached, or gone above, that value yet. and i start by checking if the 30 seconds have passed, so the code in that if statement is the only code executed. This code has worked in previous builds (that are otherwise very outdated) but they were made in older versions of unity, so i don't know if that is the reason. It's just so specific, and i can't see why it would work after 5 seconds, but not 30 seconds. The only thing i can think of is using Time.deltaTime, but i don't see how that would work, since checking what the in game time is with Time.time should work (and has worked). I really hope you can help, cause i want this game released.
Do you have value set in the editor for narrowTime, movingTime etc? These will overrule the ones in the script so it could be there are wrong numbers there. Time.time() is the correct one to use as it is the time in seconds since the game started.