Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
2
Question by hawken-2 · Jul 06, 2011 at 09:42 AM · buttoniphoneguitexturetap

Making a GUI Texture tappable on iPhone

Disclaimer: I've searched everywhere for this, including the Unity documentation.

In the Unity simulator, this works fine if I add a script like this to my GUITexture in the hierarchy:

 function OnMouseUp (){
         //do stuff
 }

However when run on the iPhone, this doesn't have any effect. After a bit of searching I tried:

 if(Input.touchCount>0){
 //do stuff
 }

This doesn't appear to do anything in the simulator or on the handset.

One thing that does work fine on the iPhone is building a GUIButton like this:

 function OnGUI() {
     
         if(GUI.Button(Rect(0,400,320,44),"I'm a code generated button!")) {
             //do stuff        
             }
     }

However this is code for dynamically drawing a button, not code for placing on a GUITexture game object.

Any clues? :(

Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by hawken-2 · Jul 06, 2011 at 09:58 AM

Actually, I fixed this by looking at some Android questions!!

Here's the ballache answer (you need to do this per button... ):

 function Update(){
     if (Input.touchCount == 1)
     {
     var touch: Touch = Input.touches[0]; 
     
     if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))
     
         {
         // do amazing things
         } 
     }
 }
Comment
Add comment · Show 2 · Share
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 reptilebeats · Jan 18, 2012 at 10:12 PM 0
Share

good stuff works great just what i was looking for simple code for a simple question which no can answer and come up with some complicated method which takes up more speed or better know as lag, some guy actually wanted to assign each one to adifferent layer

avatar image moghes · Mar 13, 2013 at 05:14 PM 0
Share

nice one! simple and clear

avatar image
0

Answer by Annihilator · Apr 05, 2012 at 12:39 PM

,how do you use this with multiple touches?

Lets say you have 2 GUITextures and you want each of them to have independent touches, how do you modify the code so that you

Comment
Add comment · Share
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
0

Answer by Annihilator · Apr 05, 2012 at 12:39 PM

how do you use this with multiple touches?

Lets say you have 2 GUITextures and you want each of them to have independent touches, how do you modify the code so that you if you touch the 1 texture if activates, touching the other activates that one aswell and releasing either of them deactivates the one released... Same works if they are touched independently

Comment
Add comment · Show 2 · Share
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 reptilebeats · Apr 05, 2012 at 01:04 PM 0
Share

i actually from the code above modded it to act perfect with multiple touches, so say in my game i can hold the acceleration and turn.

basically all you have to do is check each touch in a loop{

and in this write the code, i can post a snipit of the code later if you need it but i have to go now so i havent got time

}

avatar image save · May 28, 2012 at 09:02 PM 0
Share
 if (Input.touchCount>0) {
     for (var touch : Touch in Input.touches) {
         if (touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position)) {
             
         }
     } 
 }
avatar image
0

Answer by Orthomyxovirus · Sep 11, 2012 at 04:59 AM

I have some problem, i want do something like this:

When i tap guitexture it change from texture1 to texture2, so i combine two scripts this for tap and this:

 var texture1 : GUITexture;
 var texture2 : GUITexture;
 
 var someTexture : GUITexture;
 someTexture = texture1;
 guiTexture.texture = texture1.texture;
 
 function Update () {
 }
 
 function OnGUI() {
 
     if(GUI.Button(Rect(0,0,100,40),"Cambia fondo")){
         if(someTexture == texture1) {
             someTexture = texture2;
         } else if (someTexture == texture2) {
             someTexture = texture1;
         }   
 
     }
 }

for change GUITexture

but first what i do is check this script, it work but GUITexture are not change on screen in inspector i see changes texture1 to texture2

I want do something like this:

 var texture1 : GUITexture;
 var texture2 : GUITexture;
 
 var someTexture : GUITexture;
 someTexture = texture1;
 guiTexture.texture = texture1.texture;
 
 
 function Update(){
     if (Input.touchCount == 1)
     {
     var touch: Touch = Input.touches[0]; 
 
     if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))
 
        {
         if(someTexture == texture1) {
             someTexture = texture2;
         } else if (someTexture == texture2) {
             someTexture = texture1;
         }   
        } 
     }
 }

I search 2h for something and i cant find anything, so… somebody can help me?

Comment
Add comment · Share
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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Moving a button out of screen in iPhone 1 Answer

EXTREMELY basic button question. 2 Answers

How to make a GUI Texture play an Animation of a GameObject? 1 Answer

Help with code logic iPhone Touch FPS 0 Answers

GUITexture buttons in Android are too sensitive 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges