using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; public class StarRating : MonoBehaviour { [Header("星星設定")] public Button[] stars; public Sprite starGray; public Sprite starYellow; private int currentRating = 0; void Start() { Debug.Log("=== " + gameObject.name + " 開始初始化 ==="); // 檢查 EventSystem EventSystem eventSystem = FindObjectOfType(); if (eventSystem == null) { Debug.LogError("場景中沒有 EventSystem!"); } else { Debug.Log("EventSystem 存在: " + eventSystem.name); } // 檢查圖片 if (starGray == null) { Debug.LogError(gameObject.name + ": 灰色星星圖片沒有指派!"); } else { Debug.Log("灰色星星圖片已指派"); } if (starYellow == null) { Debug.LogError(gameObject.name + ": 黃色星星圖片沒有指派!"); } else { Debug.Log("黃色星星圖片已指派"); } Debug.Log("星星陣列大小: " + stars.Length); // 初始化每顆星星 for (int i = 0; i < stars.Length; i++) { if (stars[i] == null) { Debug.LogError("星星 " + i + " 沒有被指派!"); continue; } int starIndex = i + 1; // 設定初始圖片 Image starImage = stars[i].GetComponent(); if (starImage != null && starGray != null) { starImage.sprite = starGray; starImage.raycastTarget = true; Debug.Log("星星 " + starIndex + " 圖片設定完成,Raycast Target = " + starImage.raycastTarget); } // 檢查 Button Button button = stars[i].GetComponent