- Home /
Have a spawning issue on iOS
I can't seem to figure out this issue.
In Unity, my game plays perfectly. No spawning issues.
But when I load the game through XCode onto my iPhone the game spawns too many objects.
For example, I spawn between 2 and 6 objects which drop one after the other. Its randomized so 2 through 6 objects will spawn then after 5 seconds another 2-6 objects will spawn.
But on the iPhone, when the game starts, the objects will spawn a random amount at once. Then the game will spawn 2-6 objects regularly every 5 seconds like it should.
An even bigger issue is that after I end the game and go back to the main menu then go back into the game again. The game will spawn the same amount of objects that were on the screen when the game ended.
I'm pretty lost and frustrated. It seems something is changing when I build the game for the iPhone. Again, it works perfectly in Unity.
Any help would be greatly appreciated.
I figured it out! It was a simple ti$$anonymous$$g issue.
So what I found out is you cannot declare Time.time outside of a function or it screws everything up.
What I had:
float timer = Time.time;
This was declared outside of a function at the beginning of my script.
So I changed that code to:
float timer;
And added inside the Start():
timer = Time.time;
This fixed my spawning issue right away and it now works when I build to any device.
Your answer
Follow this Question
Related Questions
Having Trouble with Instantiating an object on an axis 2 Answers
How would I create a script that spawns objects more frequently as time goes on? 3 Answers
How Do I Add An Instantiated Object To An Array? 3 Answers
Problems with spawning items that the players can pick up - Unet 0 Answers
How do I spawn an object under another moving object at random in C#? 1 Answer