Unity is saying that ActorEquipment.actorEquipmentInstance.onEquipmentChanged += OnEquipmentChanged;
is null and thats it. No other information. (Thanks Unity, thats helpful…) Visual Studio is happy with the script/s.
Yes, I stole the script from a tutorial and tweaked it for my purposes.
I know its something to do with the Callback method thing…what every that is…(Still cant get my head around it, I have a poor IQ, therefore im not able to grasp concepts easily)
After going through it repeatedly, I cant find any reason why it would return null, despite I have no idea what im typing.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class BaseAnimatorController : MonoBehaviour {
void Awake()
{
ActorEquipment.actorEquipmentInstance.onEquipmentChanged += OnEquipmentChanged;
}
void OnEquipmentChanged(Equipment newItem, Equipment oldItem)
{
}
}
//---------------------------------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ActorEquipment : MonoBehaviour {
public static ActorEquipment actorEquipmentInstance;
void Awake()
{
actorEquipmentInstance = this;
}
public delegate void OnEquipmentChanged(Equipment newItem, Equipment oldItem);
public OnEquipmentChanged onEquipmentChanged;
public void Equip(Equipment newItem)
{
int slotIndex = (int)newItem.EquipmentType;
Equipment oldItem = Unequip(slotIndex);
if (onEquipmentChanged != null)
{
onEquipmentChanged.Invoke(newItem, oldItem);
}
currentEquipment[slotIndex] = newItem;
}
public Equipment Unequip(int slotIndex)
{
Equipment oldItem = null;
if (currentEquipment[slotIndex] != null)
{
oldItem = currentEquipment[slotIndex];
inventory.AddToInventory(oldItem);
currentEquipment[slotIndex] = null;
if (onEquipmentChanged != null)
{
onEquipmentChanged.Invoke(null, oldItem);
}
}
return oldItem;
}
}