• 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 AriesT · Aug 03, 2013 at 10:10 AM · gameobjecttriggerontriggerenterontriggerexitpop-up

OnTriggerExit overwrites OnTriggerEnter

Dear commUnity,

I currently am working on ingame text boxes which should appear when the player enters a trigger and which disappear again when leaving the trigger. However, this is not working properly. When moving the player inside the trigger, the text box only pops up for a frame. I noticed the text box only stays active at the very edge of that trigger. The player moves with a Character Controller and has no ridigbody attached.

This is the code:

 var textBox : GameObject; // The linked text box which appears when entering the trigger
 
 function OnTriggerEnter(other: Collider)
 {
     if (other.gameObject.tag == "Player")
     {
 // Activate text box
         textBox.gameObject.SetActive(true);
     }
 }
 
 function OnTriggerExit(other: Collider)
 {
     if (other.gameObject.tag == "Player")
     {
 // Deactivate text box
         textBox.gameObject.SetActive(false);
 
     }
 }

I tried using OnTriggerStay as an alternative (of course, this is the first option which comes into mind) but the issue was still there. No effect on the problem.

I can also provide an image of the only position where the text box is active constantly: Edge Of Trigger

(The black cube is the player dummy)

trigger_active.png (22.9 kB)
Comment
Add comment · Show 1
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 john-essy · Aug 03, 2013 at 10:20 AM 0
Share

Try OnTriggerStay()

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Lovrenc · Aug 03, 2013 at 12:38 PM

Once your object triggers

 OnTriggerEnter

You deactivate it by setting active to false. This means, it is not active anymore and thus wont collide anymore (It wont even be in collision detection loop anymore, but it seems it throws OnCollisionExit uppon deactivation). Try only disabling renderer.

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
avatar image
0

Answer by Nevadaes · Aug 03, 2013 at 12:07 PM

From http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnTriggerEnter.html

Note that trigger events are only sent if one of the colliders also has a rigid body attached.

It might be worth the try to add a rigid body to your character.

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 AriesT · Aug 03, 2013 at 12:24 PM 0
Share

No this does not work either. The trigger still only activates at the edge and closes the popup again when moving the player inside the trigger. $$anonymous$$aybe I need to add, I use a Probuilder trigger. However, I don't believe this causing the trouble.

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

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

Why is OnTriggerEnter2D executing multiple times before I get an OnTriggerExit2D? 1 Answer

How do I make all game objects with a certain tag appear on trigger enter? (C#) 2 Answers

Why won't the coin destroy when hit? 0 Answers

Display gui box after trigger is activated? 2 Answers

OnTriggerEnter Help? 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