Hi all,
I want to make that my variable equals 1 only when my button clicked, and when it released it will be 0.
I’m using javascript.
Thanks in advance for help
Hi all,
I want to make that my variable equals 1 only when my button clicked, and when it released it will be 0.
I’m using javascript.
Thanks in advance for help
You can use GUI.RepeatButton for things like that.
http://unity3d.com/support/documentation/ScriptReference/GUI.RepeatButton.html
GetKey sends 1 on all frames you keep pressing.
GetKeyDown sends 1 only on the frame you press, and 0 the rest of the time even if you hold down
GetKeyUp sends 1 when you release the button, and 0 any other time.
GetMouseButton and GetButton work the same way.
So I guess you are looking for
var anyVar: boolean;
function Start(){
anyvar = false;
}
function Update(){
if(Input.GetKeyDown("Jump")
anyvar = true;
else if(Input.GetKeyUp("Jump"))
anyvar = false;
}
Jump is the space bar by default, check Edit->Project Setting->Input to see what is what and change as you wish.
Or more simply:
var anyVar: boolean;
function Start(){
anyvar = false;
}
function Update(){
if(Input.GetKey("Jump")
anyvar = true;
else
anyvar = false;
}
you choose.