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
-1
Question by Fuhans92 · May 19, 2014 at 03:05 PM · c#gui

Access clicked button from the different function

Hi, I already made

GUI.Button and GUI.Box

function on the different class and whenever I want to call the GUI, I just call the class and pass the parameter needed. Right now, the GUI are shown on the screen, but I could not think about how to make the GUI clicked. I mean, whenever I clicked the GUI, maybe something like

Debug.Log("You have clicked this button");

show on the Unity Console.

Here is the class code that I am using to store the GUI.Box and GUI.Button:

 public class UserInformation{
         public static GUIContent text, informationText, tooltipText; // For the content
         public static GUIStyle style, informationStyle, tooltipStyle; // For the style
         public static Rect rect, informationRect, tooltipRect; // For the position
     
     public static void SetGUI(string content, int id, int minusWith)
         {
             // Switch with the parameter id
     
             switch(id)
             {
                     // If user selects 1 for the id, this case for the gold
                 case 1:
     
                     // Set the content, the style and the size of the box would be to the GUI.Box
                     //SetStyle(id);
     
                     // Set the GUIContent as the tooltip
                     text = new GUIContent(content);
     
                     // The GUILayoutUtility is useful because it is to fit the content
                     rect = GUILayoutUtility.GetRect(text, style);
     
                     // Set where the Rect have to be displayed
                     rect.x = Screen.width - rect.width;
                     rect.y = rect.height;
     
                     // Show the GUI as the box
                     GUI.Box(rect, text, style);
     
                     // Break it
                     break;
     
                     // If user selects 2 for the id, this case for the button
                 case 2:
     
                     // Set the content, the style and the size of the box would be to the GUI.Button
                     //SetStyle(id);
     
                     // Set the GUIContent as the tooltip
                     text = new GUIContent(content);
     
                     // The GUILayoutUtility is useful because it is to fit the content
                     rect = new Rect(0, 0, 150, 20);
     
                     // Set where the Rect have to be displayed
                     rect.x = 5;
                     rect.y = Screen.height - minusWith;
     
                     // Show the GUI as the button
                     GUI.Button(rect, text, style);
     
                     // Break it
                     break;
     
                     // If user selects 3 for the id, this case for the information
                 case 3:
     
                     // Set the content, the style and the size of the box would be to the GUI.Box
                     //SetStyle(id);
     
                     // Set the GUIContent as the tooltip
                     informationText = new GUIContent(content);
     
                     // Set the Rect
                     informationRect = new Rect(0, 0, 400, 225);
     
                     // Set where the Rect have to be displayed
                     informationRect.x = 0;
                     informationRect.y = (Screen.height / 10) - 50;
     
                     // Show the GUI as the box
                     GUI.Box(informationRect, informationText, informationStyle);
     
                     // Break it
                     break;
     
                     // If user selects 4 for the id, this case for the tooltip
                 case 4:
     
                     // Set the content, the style and the size of the box would be to the GUI.Box
                     //SetStyle(id);
     
                     // Set the GUIContent as the tooltip
                     tooltipText = new GUIContent(content);
     
                     // Set the Rect
                     tooltipRect = GUILayoutUtility.GetRect(tooltipText, tooltipStyle);
     
                     // Set where the Rect have to be displayed
                     tooltipRect.x = Screen.width - tooltipRect.width;
                     tooltipRect.y = Screen.height - tooltipRect.height;
     
                     // Show the GUI as the box
                     GUI.Box(tooltipRect, tooltipText, tooltipStyle);
     
                     // Break it
                     break;
     
     
                     // If user selects either 1, 2, 3 or 4 for the id
                 default:
     
                     // Show the error
                     Debug.LogError("You must choose between 1, 2, 3, or 4 only for the GUI!");
     
                     // Break it
                     break;
             }
     
             // End of switch
     
         } 
 }

, but this time, whenever I want to check whether the button has been clicked by doing this code: (this is just an example of many GUI that has been shown on the screen)

 if (UserInformation.SetGUI("Show Information", 2, Screen.height - 10))

it says that

cannot convert type void to bool

Basically, I want to check if the button have been clicked or not clicked yet.

Your answer much appreciated.

Thank you

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 Sisso · May 19, 2014 at 03:10 PM

You cannot convert a function that return nothing (void) into a boolean. SetGUI return nothing (void), so you can't use it in the if.

I really recommend you to start follow some unity3d/coding tutorials.

Comment
Add comment · Show 1 · 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 Fuhans92 · May 19, 2014 at 03:44 PM 0
Share

okay.. thank you very much

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

21 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

Related Questions

Set the position of GUIBox 1 Answer

Error CS1519 1 Answer

Not working gui buttons 1 Answer

Distribute terrain in zones 3 Answers

Font sizes, GUI, Iphones and even more head scracthing problems 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