I am working on a game that needs collisions with the player and enemy characters in order to do damage, however I can not get my collisions to work. I have only had this issue when the collision objects have used a nav mesh.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerStats : MonoBehaviour
{
[SerializeField] private float maxHealth;
private float currentHealth;
public healthBar healthBar;
private void Start()
{
currentHealth = maxHealth;
healthBar.SetSliderMax(maxHealth);
}
public void TakeDamage(float amount)
{
currentHealth -= amount;
healthBar.SetSlider(currentHealth);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Enemy")
{
TakeDamage(20f);
}
}
}