I’m trying to make an inventory. I made a ScriptableObject class. And it’s been working fine. But. When i run a function i made. It says that one of the variables in that ScriptableObject is missing. Even though it’s not. I’ve been trying to fix it for 2 hours now -_-
My Inventory Script(The one with the error)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class inventoryScript : MonoBehaviour {
public items itemTest;
public GameObject defaultItemSprite;
static int inventorySlotsCount = 52;
items[] slotContents = new items[inventorySlotsCount];
public GameObject[] inventorySlotsAr = new GameObject[inventorySlotsCount];
void Start() {
addItem (itemTest);
getSlots ();
}
public void addItem(items itemToAdd) { // The function with the problem
for (int i = 0; i < slotContents.Length; i++) {
if (slotContents *== null) {*
_ createItem(itemToAdd.itemSprite, inventorySlotsAr*.gameObject.transform); // Line with the problem*_
* }*
* }*
* }*
* void createItem(Sprite imageSprite, Transform slot) {*
* GameObject instance;*
* GameObject createObj = new GameObject ();*
* createObj.AddComponent ().sprite = imageSprite;*
* instance = Instantiate (createObj, slot.transform.position, slot.transform.rotation);*
* instance.transform.SetParent (slot.transform);*
* instance.transform.localScale = new Vector3 (slot.transform.localScale.x, slot.transform.localScale.y, slot.transform.localScale.z);*
* }*
* void getSlots() {*
* for (int i = 0; i < inventorySlotsCount; i++) {*
_ if (inventorySlotsAr == null) {
inventorySlotsAr = GameObject.Find (“inventorySlot (” + i.ToString() + “)”);
* }
}
}*_
}
ScriptableObject script(Has no problem that i know of)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu]
public class items : ScriptableObject {
* public Sprite itemSprite = null;*
* public string itemName = null;*
* public GameObject itemPrefab = null;*
* public int itemId;*
}
[CreateAssetMenu]
public class skills: ScriptableObject {
* string skillName;*
* int skillId;*
}
public class itemsAndSkills : MonoBehaviour {
}