x


Can you have if(no input)?

Hey, Im animating a character and id like to know if it is possible to have if(Input.GetButtonDown(none)) { //play standing animation } if it is possible or something along those lines that would be very helpful. thank you.

preferably JAVA

more ▼

asked Jul 17 '10 at 05:36 AM

Jason Hamilton gravatar image

Jason Hamilton
445 68 73 80

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Actually there is a function called "else" that will do something at all other times when it is not pressed.

Ex. (Fill in):


function Update () {
    if (Input.GetButtonDown("(BUTTON NAME HERE)")) {
        //Do Something (Ex. animation.Play();)
    }
    else {
        //Play another animation for idle position
    }
}

Ex. (All parts):


var jumpAnimation : AnimationClip;
var idleAnimation : AnimationClip;

function Update () { if (Input.GetButtonDown("Jump")) { animation.Play("jumpAnimation"); } else { animation.Play("idleAnimation"); } }

The object that you attach this script to needs to have an animation component and have the two variables have to have the animation you want to play. You should not encounter any errors from the script. If you need to, you could change the input for a different purpose.

more ▼

answered Jul 17 '10 at 06:38 AM

0V3RWR173D gravatar image

0V3RWR173D
190 10 11 25

(comments are locked)
10|3000 characters needed characters left

Yes, you would use the "else" keyword. It will be called when the "if" condition is false.

if (condition) {

}
else {

}
more ▼

answered Jul 17 '10 at 06:35 AM

Daniel 6 gravatar image

Daniel 6
541 2 4 17

(comments are locked)
10|3000 characters needed characters left

There is also Input.anyKeyDown, which will tell you if any key is pressed on the keyboard, so if(!Input.anyKeyDown) would tell you nothing is pressed.

I probably wouldn't use it for this though, the other solutions seem like what you need

more ▼

answered Jul 17 '10 at 10:15 AM

Mike 3 gravatar image

Mike 3
30.7k 10 67 256

Thank you that was exactly the answer I wanted :)

Apr 15 at 02:36 PM IrridiumMonkey
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x14

asked: Jul 17 '10 at 05:36 AM

Seen: 1361 times

Last Updated: Apr 15 at 02:36 PM