场景中有 15 个可点击的对象。数组中有 5 个标记。用户需要将正确的 5 与该标记相匹配。用户单击其中 5 个(正确的 5 个且顺序正确)。因此,每次调用单击操作时,代码都会增加索引值。该代码使用索引沿着数组移动。但索引值不断变回0。我在这里错过了什么?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class CipherClickHandler : MonoBehaviour, IPointerClickHandler
{
public Text[] alanlar = new Text[5];
private string[] clickedWords = new string[5];
private string[] solution = { "a", "b", "c", "d", "e" };
private int index = 0;
private int counter = 0;
private bool success = false;
public void OnPointerClick(PointerEventData pointerEventData)
{
if (success)
{
return;
}
else
{
if (index < 5)
{
clickedWords[index] = this.gameObject.name;
this.gameObject.SetActive(false);
alanlar[index].text = clickedWords[index];
ControlCipher(clickedWords[index]);
index += 1;
}
else
{
index = 0;
}
}
}
private void ClearBlanks()
{
...
}
private void ControlCipher(string token)
{
if (counter < 5)
{
if (token == solution[index])
{
counter++;
}
}
else
{
PuzzleSolved();
success = true;
}
}
private void PuzzleSolved()
{
...
}
private IEnumerator CoroutineSuccess()
{
...
}
}
当我在索引之后跟踪索引时< 5 control, it returns 0. When I trace after index += 1, it returns 1. But, after the next click, it again returns 0 and 1 respectively.