ScriptableObject
This is basically a set of data as a unity asset. It can be created just like any other unity asset. The advantage is that you're not storing unnecessary data or duplicate data.
Create it like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName="New Item", menuName="Item")]
public class Item : ScriptableObject
{
public string itemName;
public int itemLevel;
public Texture2D itemIcon;
}
And use it like this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemHolder : MonoBehaviour
{
public Item itemToHold;
// Start is called before the first frame update
void Start()
{
Debug.Log("I am holding {itemToHold.name}");
}
}
Saving
SO's can't be saved during runtime outside of the editor!