hey so im pretty new with unity, and ive been having problems with a script, all giving the same error,
NullReferenceException: Object reference not set to an instance of an object
HeroKill.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/Game scripts/HeroKill.cs:19)
Iv’e looked around, and it seems like it normally means you don’t have the object the script is looking for named correctly, but afaik, I have the names right?
here’s the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HeroHP : MonoBehaviour
{
public float heroHP = 100;
public Slider HP;
public float currentHP;
// Start is called before the first frame update
void Start(){
currentHP = heroHP;
}
// Update is called once per frame
public void GetHurt(float damage){
currentHP -= damage;
HP.value = currentHP; // Error Is Here
}
and i attached the screenshot of my inspector as well
any help is appreciated!
4478224–411868–Help.psd (464 KB)