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 Alanj2007 · Oct 14, 2013 at 08:25 AM · triggerongui

OnGUI not working?

For some reason, GUI not working when I'm on trigger? Why? This is the script of it. I used this type of script for door, pick up key, and call phone but GUI is not appear!

This script is for key

 var message : boolean = false;
 var LockedTrigger : Collider;
 var UnlockedTrigger : Collider;
 
 function Start()
 {
     LockedTrigger.enabled = true;
     UnlockedTrigger.enabled = false;
     gameObject.SetActive(true);
 }
 
 function OnTriggerStay(other : Collider)
 {
     if(Input.GetButton("e")){
         gameObject.SetActive(false);
         LockedTrigger.enabled = false;
         UnlockedTrigger.enabled = true;
     }
 }
 
 function OnTriggerEnter (other : Collider){
     if (other.gameObject.tag == "Player") {
         message = true;
     }
 }
      
 function OnTriggerExit (other : Collider){
     if (other.gameObject.tag == "Player") {
         message = false;
     }
 }
      
      
 function OnGUI(){
     if(message){
         GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 300, 30), "Press E to pick up Exit door key");
     }
 }
Comment
Add comment · Show 7
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 ArkaneX · Oct 14, 2013 at 08:37 AM 0
Share

Are you sure message is true in OnGUI? Could you put

 print(message);

before if statement, just for test?

avatar image Alanj2007 · Oct 14, 2013 at 08:39 AM 0
Share

I will try

avatar image vexe · Oct 14, 2013 at 08:39 AM 1
Share

The GUI in this script should work fine. However, what are you doing with LockedTrigger and UnlockedTrigger? are either of them attached to this gameObject? $$anonymous$$aybe one of them is attached, and you're disabling it, and thus the OnTriggerEnter and Exit aren't getting fired?. I have already told you here (at the end), not to use any of the Input.GetXXX family members, inside of OnTriggerStay.

avatar image Alanj2007 · Oct 14, 2013 at 08:41 AM 0
Share

$$anonymous$$essage is printed as false although I'm in the trigger

but I able to pick up that key

avatar image Alanj2007 · Oct 14, 2013 at 08:43 AM 0
Share

@vexe

Locked Trigger will appear "Door Is Locked" GUI ... Unlocked Trigger will make players able to open it by pressing E

No, it's not attached to this key

I forgot about that.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ArkaneX · Oct 14, 2013 at 08:48 AM

If message is false, then please check if it is properly set in OnTriggerEnter (maybe your player object has no Player tag set?). Additionally, you can check if OnTriggerExit is not called.

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

16 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

Related Questions

enable a canvas on trigger 2 Answers

Problem with Colider/Trigger and OnGUI function 1 Answer

Trigger 'if' statement while in TextField 2 Answers

How to have OnGUI element in a OnTriggerEnter function? 3 Answers

Adding a value after a trigger on 1 Answer


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