using UnityEngine; using TMPro; public class Game : MonoBehaviour { // Auto-bootstrap when game starts - no Editor setup needed [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] static void Bootstrap() { if (Instance != null) return; var gameGO = new GameObject("Game"); gameGO.AddComponent(); } // =========================================== // CONFIGURATION // =========================================== // Camera settings for grid view public const float CameraZoom = 28f; // Fits 20x50 grid public const float CameraMinZoom = 15f; public const float CameraMaxZoom = 35f; // References public static Game Instance { get; private set; } GridBoard gridBoard; TextMeshProUGUI scoreText; TextMeshProUGUI gameOverText; TextMeshProUGUI turnText; void Awake() { Instance = this; } void Start() { SetupCamera(); CreateUI(); CreateGridBoard(); } void SetupCamera() { var cam = Camera.main; if (cam != null) { cam.orthographic = true; cam.orthographicSize = CameraZoom; cam.transform.position = new Vector3(0, 0, -10); cam.backgroundColor = new Color(0.1f, 0.1f, 0.15f); // Add camera controller for zoom/pan var controller = cam.gameObject.AddComponent(); controller.minZoom = CameraMinZoom; controller.maxZoom = CameraMaxZoom; } } void CreateUI() { // Create Canvas var canvasGO = new GameObject("Canvas"); var canvas = canvasGO.AddComponent(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; canvasGO.AddComponent(); canvasGO.AddComponent(); // Score text (top center) var scoreGO = new GameObject("ScoreText"); scoreGO.transform.SetParent(canvasGO.transform, false); scoreText = scoreGO.AddComponent(); scoreText.text = "0 - 0"; scoreText.fontSize = 48; scoreText.alignment = TextAlignmentOptions.Center; scoreText.color = Color.white; var scoreRect = scoreGO.GetComponent(); scoreRect.anchorMin = new Vector2(0.5f, 1f); scoreRect.anchorMax = new Vector2(0.5f, 1f); scoreRect.pivot = new Vector2(0.5f, 1f); scoreRect.anchoredPosition = new Vector2(0, -20); scoreRect.sizeDelta = new Vector2(200, 60); // Turn indicator (below score) var turnGO = new GameObject("TurnText"); turnGO.transform.SetParent(canvasGO.transform, false); turnText = turnGO.AddComponent(); turnText.text = "BLUE'S TURN"; turnText.fontSize = 32; turnText.alignment = TextAlignmentOptions.Center; turnText.color = Color.blue; var turnRect = turnGO.GetComponent(); turnRect.anchorMin = new Vector2(0.5f, 1f); turnRect.anchorMax = new Vector2(0.5f, 1f); turnRect.pivot = new Vector2(0.5f, 1f); turnRect.anchoredPosition = new Vector2(0, -80); turnRect.sizeDelta = new Vector2(300, 50); // Instructions (bottom) var instructionsGO = new GameObject("InstructionsText"); instructionsGO.transform.SetParent(canvasGO.transform, false); var instructionsText = instructionsGO.AddComponent(); instructionsText.text = "Click unit to select, then click destination to move"; instructionsText.fontSize = 20; instructionsText.alignment = TextAlignmentOptions.Center; instructionsText.color = new Color(0.7f, 0.7f, 0.7f); var instrRect = instructionsGO.GetComponent(); instrRect.anchorMin = new Vector2(0.5f, 0f); instrRect.anchorMax = new Vector2(0.5f, 0f); instrRect.pivot = new Vector2(0.5f, 0f); instrRect.anchoredPosition = new Vector2(0, 20); instrRect.sizeDelta = new Vector2(500, 40); // Game over text (hidden initially) var gameOverGO = new GameObject("GameOverText"); gameOverGO.transform.SetParent(canvasGO.transform, false); gameOverText = gameOverGO.AddComponent(); gameOverText.text = ""; gameOverText.fontSize = 72; gameOverText.alignment = TextAlignmentOptions.Center; gameOverText.color = Color.white; gameOverText.gameObject.SetActive(false); var gameOverRect = gameOverGO.GetComponent(); gameOverRect.anchorMin = new Vector2(0.5f, 0.5f); gameOverRect.anchorMax = new Vector2(0.5f, 0.5f); gameOverRect.pivot = new Vector2(0.5f, 0.5f); gameOverRect.anchoredPosition = Vector2.zero; gameOverRect.sizeDelta = new Vector2(400, 100); } void CreateGridBoard() { var boardGO = new GameObject("GridBoard"); gridBoard = boardGO.AddComponent(); // Pass UI references gridBoard.scoreText = scoreText; gridBoard.gameOverText = gameOverText; gridBoard.turnText = turnText; } }