• 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 ObviouslyInsane · Aug 14, 2011 at 12:13 AM · guihideshow

Show GUI on collision

Hi everyone, I have a simple script here I'm having a small problem with:

 var showGUI = false;
 var launcherUpgrade1 : Texture2D;
 
 
 function OnTriggerEnter (col : Collider) {
         
 
 if(col.name == "Player" && GUI.enabled == false) {
 GUI.enabled = true;
 }
 
 if(GUI.enabled == true) {
 OnGUI();
 }
 
 else if(GUI.enabled == false) {
 
 return;
 }
 }
 
 
 function OnGUI () {
    GUI.Box (Rect (10,10,100,50), GUIContent("400", launcherUpgrade1));
 }

So basically when the player collides with the gameobject t$$anonymous$$s script is attached to I want it to show the GUI. However, the GUI is automatically being shown as soon as the game starts. How can I fix t$$anonymous$$s?

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
1
Best Answer

Answer by Waz · Aug 14, 2011 at 12:24 AM

You misunderstand GUI.enabled. It's not for that. It's for "greying out" UI elements. Try t$$anonymous$$s:

 var showGUI = false;
 var launcherUpgrade1 : Texture2D;
 
 function OnTriggerEnter (col : Collider) {
     if(col.name == "Player")
         showGUI  = true;
 }
 
 function OnGUI () {
    if (showGUI) {
        GUI.Box (Rect (10,10,100,50), GUIContent("400", launcherUpgrade1));
        ... rest of the GUI ...
    }
 }

Or, if you really do want it to grey out:

 function OnGUI () {
    GUI.enabled = showGUI;
    GUI.Box (Rect (10,10,100,50), GUIContent("400", launcherUpgrade1));
 }
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 ObviouslyInsane · Aug 14, 2011 at 12:34 AM 0
Share
avatar image Dune · Apr 17, 2013 at 01:39 AM 0
Share
avatar image
5

Answer by Ziad · Aug 14, 2011 at 12:27 AM

make a script and name it

GUIControllerScript.cs

 using UnityEngine;

using System.Collections;

public class GUIControllerScript : MonoBehaviour {

 public bool ShowGUI = false;

 void Start () 
 
 {
 
 }
 
 void Update () 
 {
     if (ShowGUI)
     {
         G_U_I.Instance.enabled = true;
     }
     if (!ShowGUI)
     {
         G_U_I.Instance.enabled = false;
     }
 }

 void OnTriggerEnter(Collider col)
 {
     if (col.name == "Player")
     {
         ShowGUI = true;
     }
 }


}

and t$$anonymous$$s one name it

G_U_I.cs

 using UnityEngine;

using System.Collections;

public class G_U_I : MonoBehaviour { public static G_U_I Instance;

 void Start () 
 {
     Instance = t$$anonymous$$s;
 }
 
 void Update () 
 {
 
 }


 void OnGUI()
 {
     //Put ur GUI Script here
 }

}

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 Waz · Aug 14, 2011 at 02:13 AM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

hide button 1 Answer

How to hide/unhide a GUI image when character enters trigger. 1 Answer

show gui when look certain object 2 Answers

Confusing Logic (Just need some help with what goes where) 0 Answers

Hide/Show part of a GameObject 3 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