The class BattleEnemy has a List named attackList, and antoher UnityAction named first.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class BBlackout : BattleEnemy
{
private void HeadButt()
{
Debug.Log("Headbutt");
}
private void Start()
{
first = HeadButt;
attackList.Add(first); //first attempt
attackList.Add(HeadButt); //second attempt
}
}
When either of the attempts are run, the debug window writes “NullReferenceException: Object reference not set to an instance of an object.”
Is there a specific way I am supposed to add UnityActions to a list?,The class BBlackout inherits from BattleEnemy. BattleEnemy has a List named attacklist, and a UnityAction named first.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class BBlackout : BattleEnemy
{
private void HeadButt()
{
Debug.Log("Headbutt");
}
private void Start()
{
first = HeadButt;
attackList.Add(first); //first attempt
attackList.Add(HeadButt); //second attempt
}
}
But when this code runs, the Debug menu writes “NullReferenceException: Object reference not set to an instance of an object” with either of those being used.
Is there a specific way I am supposed to add UnityActions into a list?