• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • 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.
avatar image
4
Question by Triqy · Mar 22, 2013 at 05:09 AM · androidguibuttontouchcustom

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
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ngo · Aug 03, 2013 at 05:09 AM 2
Share

Well, this is helpful~!

avatar image devil304 · Sep 19, 2013 at 05:14 PM 2
Share

Thanks, I search this more time.

avatar image NickP_2 · Jan 09, 2014 at 11:13 AM 2
Share

You saved us days of headaches!

avatar image greenevo · Mar 02, 2014 at 06:41 PM 2
Share

thank you :-)

avatar image rodude123 · May 22, 2014 at 07:38 PM 1
Share

thanks so much

Show more comments

0 Replies

  • Sort: 

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

help with touch button (android) 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges