I’m currently working on a project with a health script and a take damage script. I’ve used the script onto an enemy I made and it works perfectly. So I’m now using it on my player but I changed it a bit since the original wouldn’t work. the script problem I am having is when it comes to the take/deal damage script
it keeps giving me this error
‘Player’ does not contain a definition for ‘TakeDamage’ and no accessible extension method ‘TakeDamage’ accepting a first argument of type ‘Player’ could be found
I’ll put the code I wrote for it but I would really like it if someone could point out the problem since I am still learning
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class hittingplayer : MonoBehaviour
{
private void OncollisionEnter2d(Collision2D collision)
{
if(collision.gameObject.TryGetComponent<Player>(out Player playerComponent))
{
playerComponent.TakeDamage(1);
}
}
}