using UnityEngine; using System.Collections.Generic; public class GameManager : MonoBehaviour { public static GameManager Instance { get; private set; } [Header("Prefabs & Scene References")] [SerializeField] private GameObject diePrefab; [SerializeField] private TrayManager trayManager; [Header("Game State")] [SerializeField] private List activeDice = new List(); private void Awake() { if (Instance != null && Instance != this) Destroy(gameObject); else Instance = this; } void Start() { if (trayManager == null) { Debug.LogError("TrayManager not assigned in GameManager!", this); return; } // --- MODIFIED: Start by placing dice in the bag --- // Clear any dice from the editor for a clean start foreach(var die in FindObjectsOfType()) Destroy(die.gameObject); activeDice.Clear(); // Create initial dice (e.g., 2 for testing) CreateNewDieInBag(); CreateNewDieInBag(); } // This function should be called by your main "ROLL" button. public void OnRollButtonPressed() { Debug.Log("--- GAME MANAGER: ROLLING SELECTED DICE ---"); bool anyDiceSelected = false; foreach (DieDisplayController die in activeDice) { if (die.isSelectedForRoll) { anyDiceSelected = true; die.RollTheDie(); } } if (!anyDiceSelected) { Debug.LogWarning("Roll button pressed, but no dice were selected!"); } } // This method now places the die in the bag instead of rolling it public void CreateNewDieInBag() { if (diePrefab == null) return; // Find the next available bag slot position Vector3 startPos = trayManager.GetDiceBagPosition(activeDice.Count); GameObject newDieObject = Instantiate(diePrefab, startPos, Quaternion.identity); DieDisplayController newDieController = newDieObject.GetComponent(); if (newDieController != null) { activeDice.Add(newDieController); newDieController.name = $"Die_{activeDice.Count}"; Debug.Log($"A new die has been created in the bag at slot {activeDice.Count - 1}."); } } }