pretty new to programing tackling on everything I can however finally hit a bump. Right to it, I'm trying to attach abilities to my hero so I can serialize easier. However whenever I try to add it says
NullReferenceException: Object reference not set to an instance of an object LevelUp.Update () (at Assets/LevelUp.cs:62) and does not add the test ability. so heres the script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Hero
{
public string heroname;
public List<Ability> heroability = new List<Ability>;
public Hero(string name)
{
heroname = name;
{
ability class
[System.Serializable]
public class Ability
{
public string abilityname;
public float abilitydmg;
public Ability(string name, float damage)
{
abilityname = name;
abilitydmg = damage;
}
}
and then adding outside on a void update (gameobject is set with holder)
public class LevelUp : MonoBehaviour {
public GameObject heroOne;
public Hero hero1;
public Ability a1;
public List<Ability> test = new List<Ability>();
void Update()
{
hero1 = heroOne.GetComponent<FirstHolder>().hero1;
hero1.heroability.Add(new Ability("test", 1));
}
and this is where the error is coming from. any insight would be appreciated. Thank you!