Enemy Collision and Player Damage - Any Help Greatly Appreciated

Hello,

I’ll start out by saying I’m really new to C# and Unity. I have a script that is looking for a player collision and inflicting player damage on contact. Currently I have my little monster running about but he’s harmless unfortunately.

When my player collides with the enemy no damage is taken. I added a debug log to the script but I’m not getting anything in console. no errors or debug log. I’m guessing that means my player and enemy are not actually colliding. I have my stopping distance turned down to 0 my enemy and I practically overlap if I stand still. But no collision. I’ve added ridged bodies to both myself and the enemy, we also have capsule colliders set as triggers. I’m out of ideas. Any help would be greatly appreciated!!

using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson;

public class EnemyDamage : MonoBehaviour
{
    public int damage;
    public PlayerInventory playerInventory;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
     

        
    }

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            playerInventory.currentHealth = damage;
            Debug.Log("hello");
        }
    }
}

If they are set to triggers, then you need to use the callbacks for triggers: Unity - Scripting API: Collider.OnTriggerEnter(Collider)

Make sure you refer to the docs about what is required for each callback to be invoked.

If both the player and monster are character controllers then you don’t need to add a rigidbody and collider to them. Instead you handle the collision with OnControllerColliderHit.

This was it! I’m getting log info now. thank you so much. I’ll do better in googling next time, thank you again Spiney. I really appreciate your time. I also had both set as triggers and according to the docs they cancel each other out as well if I understood that correctly

private void OnTriggerEnter(Collider other)
{
    if (other.gameObject.tag == "Player")
    {
        playerInventory.currentHealth = damage;
        Debug.Log("hello");
    }
}