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 /
  • Help Room /
avatar image
0
Question by reinoutdejongh · Jun 26, 2016 at 03:24 PM · guigui.buttonselecting

Problem with making a tower select GUI

Dear all,

I've been searching a long time for a solution to my problem, but so far no succes.

I have created a grid of tiles and all tiles have a script attached to it. When I click on a tile, a GUI should popup with four buttons. So far, this worked for me. But now I want that, when I click anywhere else than the four buttons, the GUI disables (goes away) itself.

I have allready tried this by using the coordinates from Input.GetMouseButtonDown(0) and convert this to world coordinates. However, when I enlarge the screen, this doesn't hold up anymore. So preferably I would use the OnDeselect function, but I do not know how to use this with code made buttons.

I use this line four times to create the buttons:

 if (GUI.Button(new Rect(screenPos.x + 10, Screen.height - screenPos.y, 40, 30), "Test"))

 

So the start of the GUI looks like this:

 void OnGUI()
     {
         if (ColliderClick == true && TileIsFree == true)
         {            
             if (GUI.Button(new Rect(screenPos.x + 10, Screen.height - screenPos.y, 40, 30), "Test"))

So I would like to have a OnDeselect function that sets ColliderClick = false; Anyone that know how to do this?

Many thanks

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

Answer by reinoutdejongh · Jun 27, 2016 at 08:28 AM

I Fixed it, I used the following code:

 Vector3 screenPos = Camera.main.WorldToScreenPoint(gameObject.transform.position);
         Event e = Event.current;
         Rect windowPosZero = new Rect(screenPos.x + 10,Screen.height - screenPos.y,40,30);
 
         if (e.type == EventType.MouseDown && !windowPosZero.Contains(e.mousePosition))
         {
             ColliderClick = false;
         }

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

83 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 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 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 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 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 Button Moving with a mouse 0 Answers

Location Does Not Change 1 Answer

Not your standard power of 2 question 1 Answer

How can I pack Font Awesome 5 as a font using Text Mesh Pro? 0 Answers

Change GUI focused appearance,Change appearance of focused GUI button 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