- Home /
OnTriggerEnterNotWorking
So I'm trying to make it so that when objectA comes in contact with objectB, it prints something out, but it ain't working. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class sdf : MonoBehaviour {
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
Debug.Log("Dank");
}
Debug.Log("Dank");
}
}
And just saying, objectA has nav mesh tunrned on, and ive tried rigidbodies with no sucess. Help.
Did you tick "Is Trigger" on your $$anonymous$$esh Collider?
Here is a useful table summarizing what you need for each objects in order to make the collisions work: https://docs.unity3d.com/$$anonymous$$anual/CollidersOverview.html
I don't believe that makes any difference. $$anonymous$$ost Unity callbacks are private by default and they work just fine, don't recall this one being an exception.
Answer by adscomics · Dec 01, 2017 at 10:19 PM
I think what you wanna do is, instead of using "tag", use "CompareTag()". So have this instead:
if (other.gameObject.CompareTag("Player"))
{
Debug.Log("Dank");
}
Debug.Log("Dank");
}
Hope this helped
Check to see if both the object the script is tied to, and the object with the "Player" tag both have colliders. If so, check to make sure that the object the script is tied to has "trigger" checked off on the collider component.
Answer by NinjaISV · Dec 02, 2017 at 07:58 PM
A few things to check:
1) Are there colliders on both objects?
2) Is trigger checked in on at least one of the objects?
3) Are the colliders both of the same dimension (2D or 3D)
4) Is the code checking for triggering also in the correct dimension? OnTriggerEnter
and OnTriggerEnter2D
.
4) Does at least one of the objects have a Rigidbody (2D or 3D depending on game) on it?
https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
Excerpt:
(This message is sent to the trigger Collider and the Rigidbody (if any) that the trigger Collider belongs to, and to the Rigidbody (or the Collider if there is no Rigidbody) that touches the trigger. Notes: Trigger events are only sent if one of the Colliders also has a Rigidbody attached. Trigger events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions. OnTriggerEnter occurs on the FixedUpdate after a collision. The Colliders involved are not guaranteed to be at the point of initial contact.)
Your answer
Follow this Question
Related Questions
Collision problem in C# 4 Answers
OnTriggerEnter being called multiple times in succession? 5 Answers
C# - Problem with trigger that won't activate 1 Answer
Checking Tag of Trigger Prefab 1 Answer
OnTriggerEnter doesnt see enemy 1 Answer