I’m getting NullReference error in PlayerInventory script. I’m getting error on Type weaponType = Type.GetType(data.behaviour);. I’m not sure why the error is happening. I would appreciate it if anyone can help me with this problem.
public int Add(WeaponData data)
{
int slotNum = -1;
for (int i = 0; i < weaponSlots.Capacity; i++)
{
if (weaponSlots[i].IsEmpty())
{
slotNum = i;
break;
}
}
if (slotNum < 0)
{
return slotNum;
}
Type weaponType = Type.GetType(data.behaviour);
if (weaponType != null)
{
GameObject go = new GameObject(data.baseStats.name + " Controller");
WeaponBase spawnedWeapon = (WeaponBase)go.AddComponent(weaponType);
spawnedWeapon.transform.SetParent(transform);
spawnedWeapon.transform.localEulerAngles = Vector2.zero;
spawnedWeapon.Initialize(data);
spawnedWeapon.OnEquip();
weaponSlots[slotNum].Assign(spawnedWeapon);
if (GameManager.instance != null && GameManager.instance.choosingUpgrade)
{
GameManager.instance.EndLevelUp();
}
return slotNum;
}
return -1;
}