Trigger is not detecting tag
That's my code:
void OnTriggerEnter(Collider col)
{
Debug.Log(col.gameObject.tag);
if (col.gameObject.CompareTag("player"))
{
Debug.Log("Player died");
agent.setTrueIfHitPlayer();
instance.player.SetActive(false);
agent.AIHitThePlayer();
//Destroy(instance.player, 1);
}
else
{
agent.setFalseIfHitPlayer();
}
}
This code is in the bullet object. And it checks if the bullet touched the player. The shooter is the enemy. I have set the tags to the parent obejct. This debug: Debug.Log(col.gameObject.tag); detects all objects but not the player tag. I don't know what I'm doing wrong. Is it because it is a prefab. And I also ticked the trigger to active in the collider of the bullet. The player is not a trigger.
It goes in the trigger function but not in the if statement, because it can't detect the player tag.
Answer by Vega4Life · Dec 16, 2018 at 02:57 PM
You need to have a rigidbody on one of those objects. Slap one on the bullet and untick use gravity.
Answer by icecold043 · May 04, 2020 at 12:48 PM
Yep! Vega4Life is right, add a Rigidbody, set it to kinematic and collision detection to continous It should work fine!
Your answer
Follow this Question
Related Questions
Bullet collider disabled with player 1 Answer
Can OnTriggerEnter2D trigger again once triggered? 0 Answers
My trigger won't activate the UI when the player collides with it. 0 Answers
PLAYER NOT ACTIVATING TRIGGER WHEN ON TOP OF THE COLLIDER! IS THIS A BUG 0 Answers
Apply more damage over time?,How can I apply more damage over time? 0 Answers