Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Noah-1 · Feb 01, 2011 at 08:26 PM · guitexturebuttondetecttap

Making a button in unity iphone?

Ok I know how to make the boring buttons like:

if (GUI.Button(Rect(20,50,10,30),"Click"))

or with texture:

if (GUI.Button(Rect(10,10,50,50),btnTexture))

But how to transform a Gui texture into a button? (without using guiskin) That kind of things really improve the user experience. I know it is simple but how?

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

3 Replies

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

Answer by Bunny83 · Feb 01, 2011 at 09:27 PM

...boring buttons...

I just ignored that... :D

Well you want to use a GUTTexture. Just place a script on that gameobject that contains the GUITexture and use something like that:

Doesn't work on iPhone:

// Javascript
function OnMouseDown() {
   // I just get clicked!
}

function Update(){
   if (Input.touchCount>0)
   {
      foreach(Touch T in Input.touches)
      {
         if(T.phase = TouchPhase.Began && guiTexture.HitTest(T.position))
         {
            // Just touched the GUITexture
         }
      }
   }
}

You don't need to use TouchPhase.Began, you can also use TouchPhase.Ended

Comment
Add comment · Show 3 · 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 Noah-1 · Feb 01, 2011 at 09:43 PM 0
Share

But mouseDown isnt only for pc? I need the button to detect the touch.

avatar image Bunny83 · Feb 01, 2011 at 10:10 PM 0
Share

ahh, my bad, just hopped over the "iphone" part :D. You're right On$$anonymous$$ouseDown don't get fired on iPhone. Well, then you have to check it yourself with HitTest(). I'll edit my post

avatar image Martín Coll · Sep 14, 2012 at 12:52 PM 0
Share

it should be T.phase == TouchPhase.Began

avatar image
1
Best Answer

Answer by Noah-1 · Feb 26, 2011 at 10:03 PM

Hey guys I found a simple and cool way on how to create a button,I have seen this question like 6 or 7 times and there wasnt a correct answer anywhere.

Finally the the answer:

var recoveryTime = 10;

private var delay = 0;

function Update () { if (delay>0){delay -=1;}

if (delay == 0){ if (iPhoneInput.touchCount ==1){

       var currentTouch:iPhoneTouch = iPhoneInput.touches[0]; 

   if(currentTouch.phase ==

iPhoneTouchPhase.Began && guiTexture.HitTest(currentTouch.position)){ Application.LoadLevel ("FirstLevel");

     }
   }
          }    }

I hope it helps guys, just add the code to the GUI texture.

If this helps you, dont forget to rate....:)

Comment
Add comment · Show 3 · 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 stety2 · Aug 17, 2012 at 10:57 AM 0
Share

I can do to make it work with mul$$anonymous$$ch?

avatar image Bunny83 · Aug 17, 2012 at 11:08 AM 0
Share

@stety2: Have you read beep's answer? You just have to check all touches. Input.touches is an array.

avatar image stety2 · Aug 17, 2012 at 05:17 PM 0
Share

Sorry but I do not get it, can you please explain it to me? And show me some example please.

avatar image
1

Answer by beep · Apr 13, 2011 at 06:52 PM

Try this:

function Update () {    
    var fingerCount = 0;
    for (var touch : Touch in Input.touches) {
        if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled && guiTexture.HitTest(touch.position))
            fingerCount++;
    }
    if (fingerCount > 0) {
        // your action goes here....
    }
}

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Make a Button out of a Textured Plane 2 Answers

Buttons and images 1 Answer

GUI Button Texture only showing as small 1 Answer

Detect Mouse Click OnGUI 1 Answer

GUI buttons look fine on full screen but distorted otherwise? 0 Answers


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