- Home /
This question was
closed Sep 23, 2013 at 10:40 PM by
clunk47 for the following reason:
Question is off-topic or not relevant
This post has been wikified, any user with enough reputation can edit it.
Android GUITexture Touch
This little code is not a question, but rather a help answer. The code below is for new developers that are trying to make a GUI button for mobile devices. I thought it would be a good idea to help the newer people that are getting into game development. :) This code is in Java.
#pragma strict
static var ShowGUI = false;
function Start () {
ShowGUI = true;
}
function Update () {
//The 'ShowGUI' enables you do either view or not view the actual GUI
if(ShowGUI == true ){
guiTexture.enabled = true;
}else{
guiTexture.enabled = false;
}
if(ShowGUI == true){
if(Input.touchCount > 0 ){
for(var i : int = 0; i < Input.touchCount; i++){
var touch : Touch = Input.GetTouch(i);
if(touch.phase == TouchPhase.Began &&
guiTexture.HitTest(touch.position)){
//This space is where the action happens when you touch your custom GUI button on
//your device.
}
}
}else{
//Stops Action
}
}
}
Just Copy/Paste above script into a JS script and place it on the GUITexture you have made in your scene and there you have it. A simple Custom button. :) Cheers!
Comment
Follow this Question
Related Questions
Switching a GUIbuttons texture when holding your finger on it? 1 Answer
Button reaction time problem 1 Answer
Why this simple code doesnt work? 0 Answers
Holding GUI Button Touch to Rotate Object 0 Answers
GUI Button for Android 1 Answer