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
1
Question by Taragon · Apr 17, 2011 at 10:26 AM · ontriggerenter3dplatformtutorial

OnTrigger not working in 3DPlatformer Tutorial

In the following script, I have the player, Lerpz running into a sphere object, "QuestionMark". I have Debug.Log right after to see if ontrigger works, however am not getting an output. Would appreciate any direction. There is a character controller on Lerpz, however no rigidbody on the sphere.

var questiontrigger : boolean = false; private var mover : DroppableMover; var playerStatus : ThirdPersonStatus;

function Start () { // do we exist in the level or are we instantiated by an enemy dying? mover = GetComponent(DroppableMover); }

function OnTriggerEnter (col: Collider) { if(mover && mover.enabled) return; var playerStatus : ThirdPersonStatus = col.GetComponent(ThirdPersonStatus); Debug.Log("YES"); if(col.gameObject.name == "QuestionMark") questiontrigger = true; Destroy(this); }

//function OnTriggerExit (col: Collider) { // if(col.gameObject.name == "QuestionMark") { // questiontrigger = false; // } //}

function OnGUI () { if(questiontrigger) { GUILayout.Label("Here are your instructions for level 1");

}

}

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 MC HALO · Apr 17, 2011 at 05:09 PM 0
Share

im glad that it worked :)

1 Reply

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

Answer by MC HALO · Apr 17, 2011 at 11:23 AM

it is not name it is tag so it should be:

var questiontrigger : boolean = false;

   private var mover : DroppableMover; 

   var      playerStatus : ThirdPersonStatus;

    var QuestionMark: GameObject;

function Start () { // do we exist in the level or are we instantiated by an enemy dying?

         mover = GetComponent(DroppableMover); }

      function OnTriggerEnter (col: Collider) { 
               if(mover && mover.enabled) return; 

         var playerStatus : ThirdPersonStatus = col.GetComponent(ThirdPersonStatus);
            Debug.Log("YES");

           if(col.gameObject.tag == "QuestionMark") questiontrigger = true;                  

           }

             function OnTriggerExit (col: Collider) { 
               if(col.gameObject.tag  == "QuestionMark") { 
                 questiontrigger = false; 

                          Destroy(QuestionMark ); 
                       } 

                     }

                   function OnGUI () { 
                       if(questiontrigger) { 
                          GUILayout.Label("Here are your instructions for level 1");

                      }
                           }

i think the line :

 Destroy(this) 

was the problem because that means you are telling the script to destroy itself and then the gui function along with that destroys itself same with the OnTriggerExit. so what i add was

   Destroy(QuestionMark);

in the on trigger exit function now that will destroy the object that you collide with once it has been destroyed. and then the GUI will boolean will be set to false and etc. but make sure this script is attached to the object not the player. and the reason i changed:

 if(col.gameObject.tag  == "QuestionMark")

to:

       if(col.gameObject.tag  == "Player")

is because no we are telling the script that if the player enters the object then do the collider if he leaves the collider destroy the object he collides with.

i also created a var on top which is called :

var QuestionMark: GameObject;

now this is important once you add the script to the collider object not the player a variable will show up in the inspector mode called :

QuestionMark 

now this will be asking for the object that it needs to destroy so drag the collider object in the variable and that should be it. Don't forget not the player :)

hope this helps :)

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

No one has followed this question yet.

Related Questions

IsFinite error - not generating output on screen for OnTrigger Script 0 Answers

3D Platformer Tutorial - !IsFinite(outDistanceAlongView) Error 0 Answers

3D Platformer Tutorial: Lerpz has gone to the dark side 4 Answers

Unity Based Telegram Channel? 0 Answers

Changing specific materials onTriggerEnter 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