Hello!
At the beginning of my scene, I use Invoke to delay adding the “Player” object until an animation is complete.
This seems to work fine, but if I unload the scene with the Player object and then go back in, the Invoke call doesn’t seem to work.
Here’s the particular code:
var playerPrefab : GameObject;
function Start () {
Invoke("addPlayer", 1);
}
function addPlayer(){
var cam = GameObject.FindWithTag("MainCamera");
var newplayer = Instantiate(playerPrefab, transform.position, transform.rotation);
cam.SendMessage("setTarget", newplayer);
Destroy(gameObject);
}
I also have tried using “Awake” instead of “Start”
IsInvoking(“addPlayer”) returns true on all times… both when it works and when it doesn’t work.
Am I not using Invoke correctly? What would be a better way of doing this?
I am stupid! I just realized that the way I’m “unloading” my game is in the Pause menu. When the pause menu is open, Time.timeScale is set to 0. I never fix that (though I guess I assumed that it would reset when I load a new scene… it does not).
Setting Time.timeScale back to 1 when I quit to the menu fixes things.
-Sam
6 Likes
Ches81
March 11, 2013, 12:59pm
3
Oh damn it! I ran into the same problem. Thank you for posting your solution to this!
I have a very similar problem: if I reload a scene from my pause menu, all the InvokeRepeating commands I already called won’t stop. Setting Time.deltaTime = 1 doesn’t work either…
Thank you sooo much! I never would have found that out. You seriously made my day. Exact same issue. Thanks for the solution!!
El_boy
July 18, 2016, 4:18pm
6
Haha, same issue here, that was a tricky one! Thanks!
I had the same problem with coroutine. Thanks!
moh05
November 23, 2016, 12:09pm
8
Hello, i have the same problem, i still have Time.timeScale = 1
Any help?
Haha, thank you for pointing our little mistake
anon_57782104:
I am stupid! I just realized that the way I’m “unloading” my game is in the Pause menu. When the pause menu is open, Time.timeScale is set to 0. I never fix that (though I guess I assumed that it would reset when I load a new scene… it does not).
Setting Time.timeScale back to 1 when I quit to the menu fixes things.
-Sam
shit, I had the same problem. Now I am stupid too.