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.
↧