- Home /
How to make double buttons?
What i want to do is to script my char in a way that when the user press W and then W again the the char changes animation.I know how to change the animations...but how to do the double tap button. (W+W immidiately)
Wow. I have no idea what the answer is, but, great question!
What exactly do you mean? Do you mean if the player pushes the button twice immediately, do you want it to play a two animations (the animation from the first press, and the animation for the second press, like a combo)? Or do you want to play only one animation, but a different one if the button is double-tapped? Can you give an example from an existing game?
too bad you have no idea...but thanks for the great question.
Derek i wanna double tap the W and play one animation.Not like double jump.
Answer by DaveA · Dec 30, 2010 at 09:43 PM
Sounds like you want a 'double-click' on a key, right? Probably several ways to do it. I'd try something like this:
private var lastTapTime = 0; var tapSpeed = .5; // in seconds, bigger numbers allow more time to detect double-tap
function Update() { if (Input.GetKeyDown ("w")) { if ((Time.time - lastTapTime) < tapSpeed) { changeAnimation(); } lastTapTime = Time.time; } }
I tried using this code in my project, but it doesn't seem to be working. The double-tap code is always triggering, never once hitting the single-tap code (used as an else).
Answer by MC HALO · Dec 30, 2010 at 09:57 PM
Hi there i found a way but im not sure if its what you are looking for. This simple Java script that i created basically allows you to play to two different animation with the same button:
function Update (){
if(Input.GetKeyDown(KeyCode.O) && Input.GetKeyDown(KeyCode.O )) {
animation.Play("Jump10");
} else if (Input.GetKey(KeyCode.O)){
animation.Play("Jump11"); } }
when you hold down the O Key the Following animation will play Jump 10
and if you press it once it will play Jump 11 :) hope this helps :)
Your answer
Follow this Question
Related Questions
Can the animation editor create local rotational data? 3 Answers
Adding animation clips via script 2 Answers
Can I make animations snap to a frame? 1 Answer
How to select an animation clip by index number? 7 Answers
OnPointerDown PointerEventData clickCount not triggering on mobile device (touch) 1 Answer