using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DargCheck : MonoBehaviour { [Header("拖拽入的选项")] public int DargID = -1; [Header("正确选项")] public int Answer = -1; [Header("检测是否正确")] public bool CheckOK = false; [HideInInspector] public UiListenter[] uiListenters; public bool openCheck = false; private Vector3[] posGroup; private void Update() { if (openCheck) { CheckDargImg(); } } /// /// 检测是否拖拽入方框位置 /// private void CheckDargImg() { posGroup = new Vector3[uiListenters.Length]; for (int i = 0; i < uiListenters.Length; i++) { posGroup[i] = uiListenters[i].GetComponent().position; if (Vector3.Distance(posGroup[i], transform.GetComponent().position) < 50f) { uiListenters[i].GetComponent().position = transform.GetComponent().position; DargID = uiListenters[i].ID; break; } } openCheck = false; } public bool CheckAnswer() { if (DargID == Answer) { CheckOK = true; this.GetComponent().color = Color.green; return true; } else { CheckOK = false; this.GetComponent().color = Color.red; return false; } } }