x


How to tell unity to do something if I push a button once

This maybe easy for you guys, but I cannot figure out how to make it so that when you push a button, the action is carried out even if the button is released.

    //attacking
if (attackready == true){
     if (Input.GetButtonDown("Fire1")){
            //moveDirection.y = jumpSpeed-8;
            //moveDirection.x = 15+sliding;
            sliding--;
            moveDirection = Vector2(15+sliding, jumpSpeed-8);
            if (sliding <=-16){
            sliding = 10;

            }
            }

    }   

Yes this is very messy looking, but this is what I have for a code so far. This is also a 2d-platformer so mind the vector2. What happens is that when I do hit fire1, instead of actually sliding like i intend, the character jumps to the position and sliding variable only goes down by one.

Thanks in advance.

more ▼

asked Mar 13 '11 at 11:40 PM

Tentor gravatar image

Tentor
2 2 3 3

Nevermind, I solved it.

Mar 14 '11 at 12:33 AM Tentor
(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

Input.GetButton instead of Input.GetButtonDown

more ▼

answered Mar 14 '11 at 02:34 AM

AngryOldMan gravatar image

AngryOldMan
2.5k 12 21 47

(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:

x77
x41

asked: Mar 13 '11 at 11:40 PM

Seen: 586 times

Last Updated: Mar 13 '11 at 11:40 PM