I’m having a strange issue where my player is not taking any damage when colliding with the enemy. I have Rigidbody 2D set to both of them and the appropriate tags set, but somehow my player is not taking any damage. I am at a loss, could the sprites im using cause this?
PlayerHealthController
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHealthController : MonoBehaviour
{
public static PlayerHealthController instance;
private void awake()
{
instance = this;
}
//[HideInInspector]
public int currentHealth;
public int maxHealth;
// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth;
}
// Update is called once per frame
void Update()
{
}
public void DamagePlayer(int damageAmount)
{
currentHealth -= damageAmount;
if(currentHealth <= 0)
{
currentHealth = 0;
gameObject.SetActive(false);
}
}
}
PlayerDamage
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DamagePlayer : MonoBehaviour
{
public int damageAmount = 1;
private void onCollisionEnter2D(Collision2D other)
{
if(other.collider.gameObject.tag == "Players")
{
DealDamage();
}
}
private void onTriggerEnter2D(Collider2D other)
{
if(other.tag == "Players")
{
DealDamage();
}
}
//health controller
void DealDamage()
{
PlayerHealthController.instance.DamagePlayer(damageAmount);
}
}