- Home /
onTriggerEnter Doesn't work no matter what
I have a problem with onTriggerEnter function as it doesn't seem to be called no matter what I do. Things I have so far
Collider on both objects and Trigger checked on object I move
Rigid body on object I move
Script added to object I move
Script on the object:
#pragma strict
var trigger : boolean;
function Start () {
}
function Update () {
}
function onTriggerEnter (other:Collider) {
trigger = true;
}
function OnGUI () {
if (trigger == false) {
GUI.Label (new Rect (20, 60, 100, 30), "False");
}
if (trigger == true) {
GUI.Label (new Rect (20, 60, 100, 30), "True");
}
}
I have no idea why the trigger function hates me as I looked through a lot of other solutions and none have worked. At this point I am out of ideas why it's not working.
I feel like an idiot.. As far as I knew only 1 had to be trigger not both..
edit: never$$anonymous$$d it did need only 1 it just has a problem with mesh colliders for some reason
Yes it only needs one. If I have a player that picks up an apple by walking over it, player has collider and rigidbody, and the apple has collider with trigger checked. I haven't tested the other way around but if your moving object is trigger, it will also go through other things (like walls). $$anonymous$$aybe you knew that but wasn't sure.
Answer by tanoshimi · Sep 18, 2016 at 05:35 PM
Case sensitivity matters. The method is called OnTriggerEnter
, not onTriggerEnter
...
Answer by kasquer · Sep 19, 2016 at 01:52 PM
Problem was with my objects having mesh colliders it seems. I changed 1 of them to have a sphere collider and it instantly started working. Not sure why it happen and thankfully that object was sphere shaped.
Your answer
Follow this Question
Related Questions
OnTriggerEnter - destroy (this.gameobject) if it collides with anything 2 Answers
How to detect collision without OnCollisionEnter or OnTriggerEnter? 1 Answer
Rocket projectile damage not applied on collision (message not sent/received) 1 Answer
OnTriggerEnter function giving mixed results 1 Answer
OnTrigger event when colliders are already touching eachother 1 Answer