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 Xerend · Oct 25, 2013 at 03:01 PM · collidertriggertagsswitch

My script isn't detecting OnTriggerEnter why?

I am trying to get my car to update which lane its in through tags. I have large cubes that are triggers with the tags Lane1-6 for some reason its not detecting the collision. The car is already in a trigger box so I can try to detect it. I have checked each cube and all of them have Is Trigger set to true. I haven't set any motion to the car yet, but that shouldn't effect anything right?

Here is what I am using to detect the trigger:

  void OnTriggerEnter(Collider Hit)
     {
         switch (Hit.tag)
         {
             case "Lane1":
                 Debug.Log("Lane 1");
                 Lane = 1;
                 break;
 
             case "Lane2":
                 Debug.Log("Lane 2");
                 Lane = 2;
                 break;
 
             case "Lane3":
                 Debug.Log("Lane 3");
                 Lane = 3;
                 break;
             
             case "Lane4":
                 Debug.Log("Lane 4");
                 Lane = 4;
                 break;
 
             case "Lane5":
                 Debug.Log("Lane 5");
                 Lane = 5;
                 break;
 
             case "Lane6":
                 Debug.Log("Lane 6");
                 Lane = 6;
                 break;
         }
         if (Hit == null)
         {
             FindLane();
         }
         if (Hit.tag == "Cleaner")
         {
             GameObject.Destroy(gameObject);
         }
         
 
     }

This is going before the Start and Update functions.

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 Xerend · Oct 25, 2013 at 03:10 PM 0
Share

Sorry I forgot to mention I tried moving it around though the scene view and nothing happened. Should I try to work out the movement before the lane detection?

1 Reply

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

Answer by Dave-Carlile · Oct 25, 2013 at 03:03 PM

According to the OnTriggerEnter documentation, the trigger event happens when an object enters the trigger area. Someone please correct me if I'm wrong, but I don't believe it will happen if the object is already inside the trigger area.

Edit: I'll correct myself - the event is called even if the object starts out inside the trigger. Make sure at least one of the objects has a rigidbody component attached.

Comment
Add comment · Show 2 · 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 Xerend · Oct 25, 2013 at 03:13 PM 0
Share

Thanks for helping me understand my brain fart.

avatar image Dave-Carlile · Oct 25, 2013 at 03:15 PM 0
Share

Please accept my answer if it was helpful.

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

Undefind tag? 0 Answers

Making Sprite Disappear on Trigger 2 Answers

Trouble with light switch 3 Answers

Ball activating triggers even with a script 0 Answers

If statement not working inside switch statement 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