- Home /
Press GUI Button and make it play animation on Android
hello beautiful people, I'm trying to make a GUI.texture button that when pressed, it plays an animation of the player bringing his arm up after it plays it goes idle, and when the button is pressed again it plays the animation of the arm going down. I currently have four animations (Arm_Up_Idle, Arm_down_Idle, Arm_transit_up, Arm_transit_down)
I've tried getting the button to work and I can't even figure that out. this is what I've got:
public class ButtonGUITouch : MonoBehaviour {
public Color GUI01;
public Color GUI02;
void Start(){
GUI01 = this.guiTexture.color;
}
void Update(){
if (Input.touches.Length < 0) {
for (int i = 0; i <= Input.touches.Length; i++) {
if(this.guiTexture.HitTest(Input.GetTouch(i).position))
Debug.Log ("HELLO MUNDO");
}
}
}
}
I've been trying to figure this out for days now but cant get anything. Any help whatsoever will be amazing and credit will be given to where its do!
Answer by FirePlantGames · Jul 17, 2014 at 05:38 AM
I would suggest using coded GUI see here for limabeans:
function OnGUI()
{
if (GUI.Button(Rect(10,10,100,32),"Play Animation"))
animation.Play("Random Animation");
}
hey thanks for the response, im guessing on animation.Play("RANDO$$anonymous$$ ANI$$anonymous$$")
i put the name of the animation i want to play? also is there any way i can have it check if the arm is up? so when i press the button again it can play the arm down animation?
Your answer
Follow this Question
Related Questions
Button Touch for Android 2 Answers
Touches aren't working on Android 1 Answer
Multiple animation with single button 1 Answer
Android issues, jump force not consistent, touch not consistent 0 Answers
Android Buttons Responding Poorly To Touch Controls 2 Answers