An object reference is required for the non-static field, method, or property

I’m getting the error “An object reference is required for the non-static field, method, or property ''Character.Vitality”
This would be the BattleHUD code

public class BattleHUD : MonoBehaviour
{

    public Text nameText;
    public Text levelText;
    public Slider hpSlider;
   

    public void SetHUD(Character character)
    {
        nameText.text = Character.CharacterName;
        levelText.text = "Lvl " + Character.CharacterStat.Level;
        hpSlider.maxValue = Character.Vitality;
        hpSlider.value = Character.CurrentHP;
    }

    public void SetHP(int hp)
    {
        hpSlider.value = hp;
    }

}
}

And this would be the character code from witch i want to take the stats reference.

public class Character : MonoBehaviour
    {
        public CharacterStat Strength;
        public CharacterStat Agility;
        public CharacterStat Intelligence;
        public CharacterStat Vitality;
        public CharacterStat Level;
        public int Currenthp;
        public string CharacterName;

Hi @lockto ,

Basically your code is trying to access your Character class as if it was a static class.

My recommendation is:

  • Go to your Scene and Create a Character instance of your character by adding your Character MonoBehaviour component to a GameObject on his Inspector window (most likely the one that you’ll be using as the character);
  • Go to your BattleHUD script adding a public Character character; line of code at the beginning;
  • Replace in the same BattleHUD script the rest of the Character text to use your new character variable instead;
  • Go back to your Scene and drag and drop the GameObject that contains your Character component to the Character slot in the Inspector window of the component BattleHUD that you have in the GameObject that contains such element.

I hope it helps!