Call a objects Damage Health script on collision with a bullet?

Not sure how this process works so i’m having trouble having a bullet damage an object if it’s an enemy.

Bullet code:

private Rigidbody rb;

    public float speed;
    public float damage;

    void Start ()
    {
        rb = GetComponent<Rigidbody> ();
    }

    void Update ()
    {
        rb.velocity = transform.forward * speed;
        Destroy (gameObject, 3.0f);
    }

    void OnCollisionEnter (Collision collision)
    {
        if (//if the collision was with an enemy)
        {
            //pass bullets damage into enemy's damage method
        }
    }

Enemy code:

public float health;
   
    void Update ()
    {
        if (health <= 0)
            Destroy (gameObject);
    }

    void TakeDamage (float damage)
    {
        health -= damage;
    }

When the bullet collides, check the collider of the collision … if its tag (easy means of identification) is an enemy, then GetComponent().TakeDamage(dmg_float_value_here);
Just make that method public.
Also, as a note, tiny performance (and logical) tweak would be to simply check if the health is <= 0 after they take damage.
Since it’s not going to just drop magically for no reason, there is no need to constantly check for it in the Update loop at all. :slight_smile:
Hope that helps.