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 /
This question was closed May 10, 2013 at 07:44 AM by Fattie for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by oooooooooott · May 10, 2013 at 03:15 AM · javascriptbooleanonguiontrigger

OnGUI Script Not Working With Boolean...

Hey guys, another durpy question, but after trying to get a notification to pop up if you are in range of an object for several hours, I decided I needed to look into it. Even though this script brings up no console errors, the boolean will not change when the Player enters the Collider area. And yes, I have made sure that the Player Game object is Tagged. Any help would be appreciated!!!

 var gui : boolean = false;
 
 function OnGUI(){
   if (gui == true){
     GUI.Label (Rect (10, 10, 100, 20), "Press E to Add To Inventory");
   }
 }
 
 function OnTriggerEnter (myTrigger : Collider) { 
       if (gameObject.tag == "Player") {
           gui = true;
       }
 }
 
 function OnTriggerExit (myTrigger : Collider) {
       if (gameObject.tag == "Player") {
           gui = false;
       }
 }
Comment
Add comment · Show 2
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 oooooooooott · May 11, 2013 at 04:05 PM 0
Share

Bump Bump Bump?

avatar image oooooooooott · May 11, 2013 at 04:05 PM 0
Share

Agh, F*** You Fattie!!! At least Codecranker tried. >:P

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by codecranker · May 10, 2013 at 03:29 AM

Are you sure OnTriggerEnter is getting called? If you put a breakpoint on line 10, does it break there?

Or if you put Debug.Log(other.gameObject.tag); inside OnTriggerEnter() what does it print in the console?

Comment
Add comment · Show 5 · 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 oooooooooott · May 10, 2013 at 08:10 PM 0
Share

Actually, I tried that earlier, but this does not produce any console messages- I am wondering if this is even something wrong with my script...? Actually, can someone reopen this? I never marked this as correct, and it did not solve the problem.

avatar image codecranker · May 10, 2013 at 09:24 PM 0
Share

Well, if it doesnt produce any console messages that means OnTriggerEnter/Exit is not getting called. Did you forgot to check the 'IsTrigger' checkbox on your gameObject's collider?

You can look and compare in the table at the bottom of the page to be sure when the the trigger events are called http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html

avatar image oooooooooott · May 11, 2013 at 03:23 AM 0
Share

Actually, yes, I did. $$anonymous$$aybe you should try the script in a unity project and tell me if it works for you...?

avatar image codecranker · May 11, 2013 at 04:06 AM 0
Share

I dont think so simply adding the script in unity will work. I need to know how your scene is setup and to which gameObject you attached the script to. It might be that your object positioning is wrong or misplaced.

avatar image oooooooooott · May 11, 2013 at 04:19 AM 0
Share

I attached the script to a cube with a rigidbody, 1 other collider (For Physics) and the only other thing interacting with it is th terrain and the player. This is a prototype scene, just trying to get this to work. XP

Follow this Question

Answers Answers and Comments

14 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

Related Questions

Using Time with OnGUI Help 2 Answers

If...else statement with errors 1 Answer

Better way to delay a function for a few seconds? Javascript 1 Answer

Change Variable on Another Script 2 Answers

I need some help on inventory. 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