- Home /
Yeild Problems
Im trying to let this animation play before pausing the game and allowing a user to chose between two options. What is happening the game freezes before the animation plays then unfreezes once the player choices the option they want. Im a bit lost on this it looks right to me but i have the foggest idea how to fix this Thanks for any help with this.
Ok so i made alot of changes to the code but now it wont get out of the If statement This is where its getting stalled at other wise its working fine
if(sliderError && !onGround)
{
sliderDeploy();
//make the choice
if(Input.GetKey(KeyCode.A))
{
Debug.Log("A was pressed");
sliderError = false;
deploy = true;
}
}
This is the new sliderdeploy finction function sliderDeploy() { this.animation.CrossFade("SliderHang"); //yield WaitForSeconds(2); this.rigidbody.drag = 0.9f; yield WaitForSeconds(2);
if(sliderError)
{
Time.timeScale = 0;
SliderError();
}else
{
Time.timeScale = 1;
}
}
and here is where ity turns on and off the guitexture
function SliderError()
{
//show ppic of error sugestions
if(sliderError)
{
errorSelection.enabled = true;
}else
{
errorSelection.enabled = false;
}
}
Answer by fafase · Nov 18, 2012 at 07:29 PM
Do not setTime.timeScale to 0,you are freezing the game. Instead, wrap up everything you want to stop in an if statement or wait for the animation to be done to set timeScale to 0.
Somehow:
yield WaitForSeconds(animation["name"].length);
Time.timeScale = 0.0f;
or
while(animation["name"].isPlaying)return;
Time.timeScale = 0.0f;
Obviously all of that needs to be in a coroutine.
Also check out this article on common challenges with this kind of thing.
The idea behind is that timeScale rules the speed of your game, everythng in the FixedUpdate or using deltaTime as well as the animation are affected. Only the mouse and Gui are still able to act. That is why your animation was waiting but you could still start the game again.