- Home /
onTriggerEnter dosent work
hi guys I've got two gameObject one is a spaceship one is a star, i have on both colider
on the star I have the following script:
void OnTriggerEnter(Collider myCol){
Debug.Log ("crash");
}
when the spaceship crashes the star the debug is not working, wich means that Im not entering the ontrigger
any ideas why?
one needs a rigid body and colliders set is trigger
Answer by Fappp · Apr 25, 2015 at 03:17 PM
One of the colliders has to be set to Trigger. There's a checkbox saying "Is Trigger" in the inspector window. Enable it on one of the objects.
If you also need the boxCollider for physics, add another one who is not marked as trigger.
yes i already did it, one the star is with the isTrigger and the spaceship is without
still the onTrigger dosent work
Also one has a rigidbody attached? As Fir3stormStudio mentions above?
Answer by carlqwe · Apr 26, 2015 at 11:36 AM
Tag your star as "star", add two box colliders to both and check the "Is Trigger". Then change the script to:
void OnTriggerEnter(Collider myCol){ if(myCol.Tag == "star"){ Debug.Log ("crash"); }
Atatch the script to your spaceship
(Im sorry if im wrong, im not that good with C#, im more of a JavaScript guy)
Your answer
Follow this Question
Related Questions
Collision Detection without a RigidBody 2 Answers
Collision not detected 3 Answers
Collision problem in C# 4 Answers
OnTrigger event when colliders are already touching eachother 1 Answer
2 objects collide, need to destroy one 2 Answers