- Home /
Holding GUI Button Touch to Rotate Object
How to make an object rotates if you hold the GUI Button ? For instance : Turn Left Button, if you pressing (hold) turn left button, the object will rotates to the left till you lift your hand (TouchPhase.Ended).
Here's my script
if(GUILayout.Button(someTextures[10])){
if(Input.touches.Length > 0 && Input.touches[0].phase == TouchPhase.Began){
rxz = -1 * 10;
rxz *= Time.deltaTime;
}else if (Input.touches.Length > 0 && Input.touches[0].phase == TouchPhase.Ended) rxz = 0;
//cnt.isPressing[1] = true;
}
rxz is float = 0. at function update() prnt.transform.Rotate(0,rxz,0);
I also have a problem in launching the object for the first time. For Instance : I hold the GUI Button, it was directly become 1.50 (it should be clamping from 0 to 1.50) i don't know how to say.here's my another script
if(isPressing[0]){
if(Input.touches.Length >0){
if(Input.touches[0].phase == TouchPhase.Began){
start = Time.timeSinceLevelLoad;
gui.ShowMe(true);
}else if(Input.touches[0].phase == TouchPhase.Ended){
end = Time.timeSinceLevelLoad;
gui.ShowMe(false);
hint.ShowHint(power.ToString("f2"),1.5, false);
StopMe();
force = power*speed; // here you compare the 2 values I had to multiply by 20 to get it up (that's what she says) but you might have to alter this eqution to get what you want
if(throwingSFX ){
audio.Stop();
audio.clip = throwingSFX[Random.Range(0,throwingSFX.length)];
audio.Play();
}
}
}
}
from another GUI Script if(GUILayout.Button(someTextures[8]))cnt.isPressing[0] = true;
Your scripts look very complex for a unearthly reason.
Use the TouchDown and TouchUp to define that on the Button.
Very simple to look in the referance @ Well, honestly i would just bing it. Lol search the reference on Bing or Google with the ButtonDown xD.
I hoped I poped a idea into yur $$anonymous$$d.
Your answer
Follow this Question
Related Questions
Switching a GUIbuttons texture when holding your finger on it? 1 Answer
Android GUITexture Touch 0 Answers
Button reaction time problem 1 Answer
Why this simple code doesnt work? 0 Answers
Android Button Screen 1 Answer