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 Videogamedeveloper · Jan 28, 2015 at 11:10 AM · guitriggerontriggerenterontriggerexitguibox

Display gui box after trigger is activated?

Hello I am making a 2D game and I would like to know how to make a gui box (the default gui things) appear after a trigger is activated. This is my script (I have two ones since I have a gameobject to display the guibox) The first script is named "badsweet"

 #pragma strict
 
 var offsetY : float = 40;
 var sizeX : float = 100;
 var sizeY : float = 40;
 
 function OnGUI () 
 {
     if (youdied1.guiShow == "true");
     {
         GUI.Box (new Rect (Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), "You Died, Press R to Restart Level");
     }
 }


The second one is called "youdied1"

 #pragma strict
 
 static var guiShow;
 
 function OnTriggerEnter2D (other : Collider2D)
 {
     if(other.tag == "Player")
     {
         guiShow = true;
     }
 }
 
 function OnTriggerExit2D (other : Collider2D)
 {
     if(other.tag == "Player")
     {
         guiShow = true;
     }
 }



With the code applied as it is now the gui box is constantly being displayed.Sorry if this sounds overly complicated. 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by chintan_shroff · Feb 13, 2015 at 01:42 AM

it constantly shows because you have not initiated the bool guiShow as false in the beginning of the code.

 static var guiShow = false;
Comment
Add comment · Show 3 · 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 chintan_shroff · May 21, 2015 at 04:06 PM 0
Share

please upvote if the answer is correct

avatar image EightbitPoe · May 21, 2015 at 04:16 PM 0
Share

Bool always start as "false", I guess

avatar image chintan_shroff · May 21, 2015 at 04:26 PM 0
Share

Thanks, being on these forums is so enlightening. I am very new to program$$anonymous$$g and Unity and am trying to learn more everyday. Thanks again

avatar image
0

Answer by EightbitPoe · May 21, 2015 at 04:26 PM

I'm not used to javascript, but try using

 if (youdied1.guiShow)

or

 if (youdied1.guiShow == true)

I guess that may be the problem

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

OnTriggerEnter/Exit called unexpectedly 2 Answers

Trigger on MeshCollider Only Seems To Work at Edges of Mesh 1 Answer

Get WHICH trigger for OnTriggerEnter? 1 Answer

Get a texture to appear, always facing the camera, when a trigger is entered? 1 Answer

OnTriggerExit overwrites OnTriggerEnter 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