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 DarkArtsProdigy · Aug 09, 2013 at 08:55 PM · guiprogramming

On Button Press, Show GUI Window

I'm making a horror RPG game and I am currently working on the NPC's. I have the characters and animations done I now need to be able to interact with the NPC's. Right now I have a script that shows a button that says "Talk to Grandpa Joe". This button is only shown when the play activates the trigger that is surrounding Grandpa Joe. Once the character leaves the trigger area, the button disappears.

Now I need help. I've searched Google, Bing, and Yahoo trying to find out how I can make a GUI Window appear once I press the "Talk to Grandpa Joe" button. This window is meant for dialogue yet I can't get a GUI window to appear on button press. Can anyone please help me?

Here's a copy of the script I'm using:

[CODE]
var toggleGUI : boolean;

     function OnTriggerEnter (other : Collider) {
     toggleGUI = true;
     }
      
     function OnTriggerExit (other : Collider) {
     toggleGUI = false;
     }
      
     function OnGUI () {
     if (toggleGUI == true)
     GUI.Button (Rect (450,450,200,30), "Talk to Grandpa Joe");
     } 

[/CODE]

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by hamcav · Aug 09, 2013 at 09:57 PM

....Try this ....

 var toggleWindow :bool = false;
 
 
 function OnGUI () {
 
  if (toggleGUI == true){
 
   if(GUI.Button (Rect (450,450,200,30), "Talk to Grandpa Joe"))
 
     toggleWindow = true;
     }
     
 if (toggleWindow == true)
 
  windowRect = GUILayout.Window (0, windowRect, 0, "My Window");
 

}

tell me if any problems occur

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 DarkArtsProdigy · Aug 10, 2013 at 12:22 AM 0
Share

You don't know how happy I am! You helped me out a ton. I modified the code to have a GUI.Box than a window. But thanks so much!

avatar image hamcav · Aug 10, 2013 at 11:55 AM 0
Share

you are welcome

avatar image
1

Answer by zombience · Aug 09, 2013 at 09:43 PM

put the GUI.Button inside an if statement. seems somewhat counterintuitive, but it's how it works.

so, putting the full code for the GUI button in will render the button, and having it inside an IF statement will receive whether it has been pressed or not.

Check out the documentation: http://docs.unity3d.com/Documentation/ScriptReference/GUI.Button.html

 if (GUI.Button(Rect(10,10,50,50),btnTexture))
             Debug.Log("Clicked the button with an image");
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

17 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

Related Questions

Multiple Cars not working 1 Answer

need a little help converting a float var to a .ToString 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Create big city for car game? 2 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