Cant detect tag on trigger collision

I am making a unity3d fps shooter i on my bullets is a trigger collider wich detects a gameobject with the tag Enemy but when i shoot it does not detect the enemy
here is my script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bulletscript : MonoBehaviour
{

    public float Speed = 20;


    private void Start()
    {
        StartCoroutine("Despawn",10f);
    }
    void Update()
    {
        transform.Translate(Vector3.forward * Speed * Time.deltaTime);
    }

    public IEnumerator Despawn(float DespawnTime)
    {
        yield return new WaitForSeconds(DespawnTime);
        Destroy(gameObject);
    }
// The 
Problem !!!!!!!!
    public void OnTriggerEnter(Collider Coll)
    {
        Debug.Log("HIT");
        if (Coll.gameObject.tag == "Enemy")
        {
            Debug.Log("HitEnemy");
            EnemyController Enemy = Coll.GetComponent<EnemyController>();
            Enemy.health = Enemy.health - 10f;
            Destroy(gameObject);
        }
    }
}

Hi,

Could you format your code properly, please?

Triggers detect non-trigger colliders only. Have you also tested the OnCollisionEnter method?

it detects a collider on the zombie but it does not detect the tag i also tried oncollisionenter but it also did not work

So “HIT” does appear in your console? If so, log the tag of the collider/ colliding game object into your console. C# is case-sensitive, so make sure the tag is spelt correctly. There mustn’t be a blank space behind the tag because your code is checking for “Enemy”, not "Enemy ".

hit apeared in the console but i found out after logging the tag that it hit the player but after removing the collision between player and projectiles layers it did not log anything after hittings things even tho they have a collider and a tag

sorry i forgot that you need a rigidbody component to make ontriggerenter work and i did not have that on my enemy becouse its a navagent wich does not need one thanks for helping anyway

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.