I want to give delay to my game in the starting and don’t want to move or work any object except the main game players Animation.
3 Answers
3Hi,
I never try something like that.
But you could try to write a script that will disable the GameObject in Awake(). In Update(), you wait until your delay passed, and then enable and destroy your component.
Or maybe, write a script that will disable all GameObjects in the scene except the one you want and wait for the delay to enable.
A solution I’ve used before that is quite flexible if your game has a lot of pausing and resuming in it is to broadcast a message called “OnPause” or something similarly named.
Any gameobjects that you want to receive it should implement the method OnPause (to receive the message) and do some conditional logic probably involving a ‘paused’ boolean. So you can do something like this in Update():
bool paused = true;
void Update()
{
// only do some stuff if paused is false
if (!paused)
{
doSomeStuff();
}
}
void OnPause()
{
paused = true;
}
You can also implement a resume message to unpause any currently paused gameobjects by setting the ‘paused’ boolean back to false;
void OnResume()
{
paused = false;
}
With the code above all of your gameobjects will start paused until you broadcast the “OnResume” message.
In addition to the previous comment… You want to Disable your rigid bodies when you are on pause, and re enable them on resume.
Have you tried Time.timeScale = 0; ?
– DeveshPandeyHe specified "except the main game players Animation". I'm not sure that your solution can handle this case.
– MikiloOh YES, I forgot that animation will stopped when timeScale = 0, sorry. I suggest the answer by "Nguyen Michaël".
– DeveshPandey