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 Saint34x · Jul 19, 2013 at 09:00 PM · guiinputtouch

how to a make a touch button open a menu while finger is down?

Hey every body! i have a Touch Gui Question.

basicly i want to have 3 buttons on my screen. then when i hold my finger on one it opens another menu then with out taking my finger off i slide it to the option i want to select then release thus selecting the option. i've made a very rough idea of what im after below.

so im looking for someone to point me in the right direction of how to do this. an example would be great (i use JS) but i would be more than happy just to be told "hey look into menu.hold.GUIbutton " (i know thats not real but if i knew the real one this question would be shorter.)

thanks in advance for all your help guys! you are the best!

-Mike

alt text

alt text

screen shot 2013-07-19 at 3.41.47 pm.png (46.1 kB)
screen shot 2013-07-19 at 3.41.57 pm.png (69.9 kB)
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

1 Reply

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

Answer by robertbu · Jul 19, 2013 at 09:31 PM

With GUI you can use Rect.Contains():

 #pragma strict
 
 private var rectControl = Rect(0,50,100,50);
 private var rectSlave1  = Rect(125,25,100,50);
 private var rectSlave2  = Rect(125,100,100,50);
 
 private var display = false;
 
 function OnGUI() {
 
     GUI.Box(rectControl, "master");
     
     var e = Event.current;
     
     if (e.type == EventType.MouseDown && rectControl.Contains(e.mousePosition))
       display = true;
     
     if (display) {
         GUI.Box(rectSlave1, "slave1");
         GUI.Box(rectSlave2, "slave2");
     }
 
    if (e.type == EventType.MouseUp) {
        if (display) {
           if (rectSlave1.Contains(e.mousePosition)) {
               Debug.Log("Selected button 1");
           }
           else if (rectSlave2.Contains(e.mousePosition)) {
               Debug.Log("Selected button 2");
           }
        }
        display = false;
    }
 }

You can replace the GUI.Box() calls with GUI.DrawTexture() to get the textures like you have in your drawing.

Comment
Add comment · Show 5 · 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 Saint34x · Jul 20, 2013 at 03:22 AM 0
Share

this works great for my computer but how would i set this up with a touch based controls? could i somehow use touchPhase.began and touchPhase.End?

avatar image robertbu · Jul 20, 2013 at 06:06 AM 0
Share

I don't use GUI for my interface work. I use EZGUI. So my understanding of GUI is not as strong as I would like. According to what I've read, you should be able to execute the above code on a touch screen without change. Unity will convert touch to the mouse events for GUI. If I had my $$anonymous$$ac here, I'd test it to be sure. Some of the posts indicated that GUI was processor intensive for touch screens, but those posts were old, so I don't know if that is still true.

If for some reason you end up using the Touch interface, be aware it returns Screen coordinates and GUI is in GUI coordinates.

avatar image Saint34x · Jul 21, 2013 at 11:52 PM 0
Share

this code worked on my unity remote android tablet. thansk so much!

avatar image Saint34x · Jul 22, 2013 at 10:08 PM 0
Share

so i tried to add textures to this and for the life of me i cant get it to work. i've replaced all the BUI.box wit GUI.Textures, i also changed the rectCont (and the others) to a texture(something i read online that i needed to do if i dont i get the error No appropriate version of 'UnityEngine.GUI.DrawTexture' for the argument list '(UnityEngine.Rect, String)' was found.) once i did that tho i get 'Contains' is not a member of 'UnityEngine.Texture'.

avatar image robertbu · Jul 23, 2013 at 03:30 AM 0
Share

Here is the above script changed to use textures. I just change the GUI.Box() calls to GUI.DrawTexture() calls. You need to drag and drop your textures onto the three variables in the inspector. It works fine in the editor:

 #pragma strict
 
 var tex$$anonymous$$aster : Texture;
 var texSlave1 : Texture;
 var texSlave2 : Texture;
  
 private var rectControl = Rect(0,50,100,50);
 private var rectSlave1  = Rect(125,25,100,50);
 private var rectSlave2  = Rect(125,100,100,50);
  
 private var display = false;
  
 function OnGUI() {
  
     GUI.DrawTexture(rectControl, tex$$anonymous$$aster);
  
     var e = Event.current;
  
     if (e.type == EventType.$$anonymous$$ouseDown && rectControl.Contains(e.mousePosition))
       display = true;
  
     if (display) {
        GUI.DrawTexture(rectSlave1, texSlave1);
        GUI.DrawTexture(rectSlave2, texSlave2);
     }
  
    if (e.type == EventType.$$anonymous$$ouseUp) {
        if (display) {
           if (rectSlave1.Contains(e.mousePosition)) {
               Debug.Log("Selected button 1");
           }
           else if (rectSlave2.Contains(e.mousePosition)) {
               Debug.Log("Selected button 2");
           }
        }
        display = false;
    }
 }

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

16 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

Related Questions

GUI texture touch input problem 1 Answer

How would I implement a GUI texture that acts as a slider? 0 Answers

Look Stick for FPS Games on Mobile Platforms 1 Answer

Mouse and Oculus Touch Controller Inputs 0 Answers

How do I get a GUI Texture Button to act as a Input Key such as a T button on a key bored or so? 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