Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Feb 20, 2017 at 07:20 PM by tanoshimi for the following reason:

Other

avatar image
0
Question by egerke · Feb 20, 2017 at 10:20 AM · triggerontriggerentertutorialtutorialsspace shooter

OnTriggerEnter Not working in sample project

I have been working on the sample project: Space shooter but when I wrote the DestroyByContact script, the OnTriggerEnter is never called, I even tried adding a console command to see if it gets called but it doesn't.:

 public class ExampleClass : MonoBehaviour
 {
     void OnTriggerEnter(Collider other)
     {
         Debug.Log("Triggered");
         Destroy(other.gameObject);
         Destroy(gameObject);
     }
 }

Both colliding objects have a Rigidbody and a Collider, with Is trigger checked, so I have no idea what is wrong.

EDIT: There's a second script on the object and integrating this code into that said script produces the intended result, so the issue only presists if there are two separate scripts. The unified script:

 public float tumble;
 private Rigidbody rb;

 void Start()
 {
     rb = GetComponent<Rigidbody>();
     rb.angularVelocity = Random.insideUnitSphere * tumble;
 }
 void OnTriggerEnter(Collider other)
 {
     Debug.Log("Triggered");
     Destroy(other.gameObject);
     Destroy(gameObject);
 }
Comment
Add comment
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

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by egerke · Feb 20, 2017 at 07:42 PM

Found the culprit. The problem was that I pasted another monobehaviour class inside the pre-created one from Unity's scripting refrence. So above the "public class ExampleClass : MonoBehaviour" line in the original code there was another similar class with a different name, that ended up containing it. Removed the extra class and now everything works.

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 jwulf · Feb 20, 2017 at 03:19 PM

Did you check the layers both objects are on, and whether collision detection between those is active or not in the project's Phsyics-Settings?

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 egerke · Feb 20, 2017 at 03:34 PM 0
Share

Both objects are in the Default layer, and collision is turned on for them in physics settings.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

In-Game Tutorial with special actions in special areas. (Shooter) 0 Answers

How do I ignore trigger objects for collision? 0 Answers

How to check if player is re-entering the same trigger? 4 Answers

triggering a door to open with a button 1 Answer

Trying to create a gameover trigger with enemy. 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