54 lines
1.2 KiB
C#
54 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
|
|
// GameItemManager.cs
|
|
// Responsible for managing the game items
|
|
public class GameItemManager : MonoBehaviour
|
|
{
|
|
public static GameItemManager Instance;
|
|
public List<GameItem> gameItems = new();
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
Debug.Log("GameItem Manager Start");
|
|
InitializeGameItems();
|
|
}
|
|
|
|
|
|
public void AddItem(GameItem item)
|
|
{
|
|
gameItems.Add(item);
|
|
Debug.Log("Added item: " + item.name);
|
|
}
|
|
|
|
public void RemoveItem(GameItem item)
|
|
{
|
|
gameItems.Remove(item);
|
|
Debug.Log("Removed item: " + item.name);
|
|
}
|
|
|
|
|
|
public void InitializeGameItems()
|
|
{
|
|
// Add predefined items to the inventory list
|
|
// Example items (replace with your actual items)
|
|
Debug.Log("Initializing items from Resources/GameItems");
|
|
var items = Resources.LoadAll<GameItem>("GameItems");
|
|
|
|
foreach (var item in items) AddItem(item);
|
|
}
|
|
} |