- Home /
wait seconds before it's possible to press a key
Hey everyone.
My problem is, how to fix this.
If an animation is playing, it's impossible to press the left and right mousebutton. So you need to wait till the animation end. then you can press them. How to do that?
Please help.
I thought something with yield WaitForSeconds()?
Thanks in advance.
Answer by ByteSheep · Jan 18, 2012 at 03:27 AM
I believe you don't have to go as complicated as using yield etc, you can just check whether the animation has stopped playing:
if(!animation.IsPlaying("Animation Name"))
{
if(//mouse input)
{
//animation isn't playing and mouse got pressed so move
}
}
Not sure if IsPlaying is the proper spelling, it might be isPlaying but you can just try it out - hope this helps :D
this is what i got, and it still don't works.
if(Input.Get$$anonymous$$ouseButton (1))
{
//animation isn't playing and mouse got pressed so move
}
$$anonymous$$aybe i should replace
"//animation isn't playing and mouse got pressed so move" in something else?
But i don't know in what.
Some help please
Here's an example of how to use this, we'll use an animation called TestAnimation just to show you what it should probably look like:
if(!animation.IsPlaying("TestAnimation")) {
if(Input.Get$$anonymous$$ouseButton (1)) {
//animation isn't playing and mouse got pressed so play animation
animation.Play("TestAnimation"); }
}
It's as simple as that just replace "TestAnimation" with the name of your actual animation that you want to play when mouse is pressed. If you still have troubles or you get errors let me know :)
Are you getting errors? Or is it not giving you the affect you want? The script above should be checking whether a certain animation is playing and if it isn't, then if the player presses the mouse button the animation can play.. Is the animation looping? cause if it doesn't stop playing then this code is useless. I need a little more info on what exactly is or isn't happening.
So, the problem is that you can not aim when the reload animation is playing, yes? And you want to be able to use the right mouse button to aim, even if the reload animation is playing? WEll, even if this isn't your problem, I believe you will need to post the controller code if anyone is going to be able to help you.
Your answer
Follow this Question
Related Questions
Unity Animation Window - Bizarre Animation Length Bug 4 Answers
Door animation after press a key 2 Answers
play animation when press key 2 Answers
Animation controller 2 Answers
Animation script 1 Answer