|
sorry for my english, i have 1 button i need to chick if it is being pressed or held down how do i do this
(comments are locked)
|
|
You can use Input.GetButton("buttonName"): this function returns true while the button is pressed. There are equivalents for keys (Input.GetKey("a"), for instance) and for GUI ( GUI.RepeatButton) EDITED: Well, doing what you want with GUI buttons is more complicated than I supposed: contrary to what I thought, RepeatButton doesn't return true while pressed - it actually returns true and false alternately each OnGUI! This complicates things, because there's no steady state to rely on.
var speed: float;
var timeThreshold: float = 0.6; // 600mS to select high speed
private var speedButton = false; // current button state
private var lastState = false; // last button state
private var speedTime: float = 0; // time measurement
function OnGUI(){
// create a steady state result for RepeatButton:
// set speedButton when RepeatButton is true...
if (GUI.RepeatButton(Rect(10,10,200,100), "Speed")){
speedButton = true;
}
// and reset it when mouse button released:
speedButton &= Input.GetMouseButton(0);
// now speedButton can be verified:
if (speedButton != lastState){ // if button changed state...
lastState = speedButton; // register current state
if (speedButton){
// if button down define the threshold time
speedTime = Time.time + timeThreshold;
} else {
// if button up select speed according to time elapsed
speed = (Time.time > speedTime)? 10 : 5;
}
}
}
but how do i make them the same button
May 12 '12 at 05:05 PM
zeuo
sorry it didnt work i replaced the speed =5 with print(low speed) and when i turn the game one the low speed is always there even with out pressing the button. my programming skills arnt good so i dont know how to fix it
May 12 '12 at 05:46 PM
zeuo
Ok, I'll check this - this logic is always confusing!
May 12 '12 at 06:19 PM
aldonaletto
Dear God! RepeatButton actually returns true and false alternately while pressed, what invalidates my previous algorithm!
May 12 '12 at 11:36 PM
aldonaletto
(comments are locked)
|


By button, do you mean keyboard, mouse or GUI?
And please read the manual, because your answer is there (for any of the case above).
its gui, when i read the script reference it talked about the button and the GUI.RepeatButton but they are separate i want them to be the same button