- Home /
How can you check for player input during specific frames of an animation?
I'm currently using animation events that call on a function that checks for mouse down, but it's extremely brute force for what I'm trying to do and requires too much precision in timing to make it functional for a human being. However, I don't have enough experience with Unity to come up with a different method.
[I'm programming a very simple jump rope game, and I'm trying to check to see if the player has clicked at the right time to perform a successful jump.]
Any suggestions?
Answer by s_awali · Dec 06, 2018 at 08:44 AM
In your case, I suggest you use animation events to set a flag to your script, and check for player input in the Update function. If the player press the mouse button down when the flag is true, he proceed, otherwise it's a game over.
public bool RightTime = false;
void Update ()
{
if(Input.GetMouseButton(0))
{
if (RightTime)
{
// player pressed the left mouse button at the right time
}
else
{
// player missed
}
}
}
Then use the animation event of your animation to set RightTime.
Your answer
Follow this Question
Related Questions
GetButton will only play animation when held down 2 Answers
Help with an animation script that works with multiple objects. 0 Answers
Yeild Problems 1 Answer
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
How do you apply animations to characters with FPS input controls? 1 Answer