- Home /
Android Button
How do you make a button for android. Like you press on it and it reacts how you do that?
What is your button made of? GUITexture or a 3D object?
Use Input.Touches to find out where the user tapped/touched the device, and then check if it is within the bounds of your button.
If you like an answer, then please mark it as "answered", ins$$anonymous$$d of simply saying he is right in the comments.
Answer by Sajidfarooq · Aug 23, 2013 at 07:07 PM
As I said earlier, the solution involves obtaining the touch position via input.touches . Then, simply check if the touch occurred within the bounds of the GUITexture:
void Update()
{
foreach (Touch touch in Input.touches)
{
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
{
if (guiTexture.HitTest(new Vector3(touch.position.x, touch.position.y, 0 ))
{
//Do something here on button click
}
}
}
}
Answer by ejpaari · Aug 23, 2013 at 07:07 PM
GUI Button works for Android aswel: http://docs.unity3d.com/Documentation/ScriptReference/GUI.Button.html
Answer by Concore Dev · Aug 23, 2013 at 08:31 PM
Im not a begginer this is my frirst time on android
Please read the UnityAnswers FAQ. This question was supposed to be a comment ins$$anonymous$$d. Also, please mark a question as "answered" if it answers your question so that others, who have the same question, can benefit.