You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.6 KiB
67 lines
1.6 KiB
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();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检测是否拖拽入方框位置
|
|
/// </summary>
|
|
private void CheckDargImg()
|
|
{
|
|
posGroup = new Vector3[uiListenters.Length];
|
|
for (int i = 0; i < uiListenters.Length; i++)
|
|
{
|
|
posGroup[i] = uiListenters[i].GetComponent<RectTransform>().position;
|
|
if (Vector3.Distance(posGroup[i], transform.GetComponent<RectTransform>().position) < 50f)
|
|
{
|
|
uiListenters[i].GetComponent<RectTransform>().position = transform.GetComponent<RectTransform>().position;
|
|
DargID = uiListenters[i].ID;
|
|
break;
|
|
}
|
|
}
|
|
openCheck = false;
|
|
}
|
|
|
|
public bool CheckAnswer()
|
|
{
|
|
if (DargID == Answer)
|
|
{
|
|
CheckOK = true;
|
|
this.GetComponent<Image>().color = Color.green;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
CheckOK = false;
|
|
this.GetComponent<Image>().color = Color.red;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|