RiftMayhem/Assets/Scripts/Items/ItemIndexer.cs
Pedro Gomes 2e12515870 Multiple fix and updates
- Fix parentscript missing from npc's
- Reworked save/load data
- Character data, player coins, character inventory and equipped items now properly saved and loaded
2024-05-18 01:38:28 +01:00

49 lines
1.3 KiB
C#

using Kryz.CharacterStats.Examples;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemIndexer : MonoBehaviour
{
#region Singleton
private static ItemIndexer _instance;
// Public reference to the singleton instance
public static ItemIndexer Instance
{
get
{
// If the instance doesn't exist, try to find it in the scene
if (_instance == null)
{
_instance = FindObjectOfType<ItemIndexer>();
// If it's still null, create a new GameObject and add the component
if (_instance == null)
{
GameObject singletonObject = new GameObject(typeof(ItemIndexer).Name);
_instance = singletonObject.AddComponent<ItemIndexer>();
}
}
return _instance;
}
}
#endregion
public List<Item> Items = new List<Item>();
protected void Awake()
{
// Ensure there's only one instance
if (_instance != null && _instance != this)
{
Destroy(gameObject);
return;
}
// If this is the first instance, set it as the singleton
_instance = this;
DontDestroyOnLoad(gameObject);
}
}