我在 for loop pf OnGUI() 方法中打印 GUI 元素时遇到问题。在下面列出的代码中,我创建了用户单击 GUI.Box 的 GUI.Label:
public List<string> messages = new List<string>();
int dialogueMsg = 0;
void OnGUI()
{
Event currentEvent = Event.current;
if (enabled)
{
GUI.BeginGroup(new Rect(Screen.width / 8, Screen.height / 4 + Screen.height / 2, Screen.width - Screen.width / 4, Screen.height / 4));
GUI.Box(new Rect(0, 0, Screen.width - Screen.width / 4, Screen.height / 4), "");
if (currentEvent.button == 0 && currentEvent.type == EventType.mouseDown)
{
for (int i = 0; i < messages.Count; i ++)
{
if (dialogueMsg < messages.Count)
{
print(dialogueMsg);
print(messages[dialogueMsg]);
GUI.Label(new Rect(25, 25, Screen.width - Screen.width / 4, Screen.height / 4), messages[dialogueMsg]);
++dialogueMsg;
break;
}
else
{
enabled = !enabled;
break;
}
}
}
GUI.EndGroup();
}
}
当用户点击时 - 除了打印正确的值dialogMsg和messages[dialogueMsg]之外,什么都没有发生。我究竟做错了什么?有人熟悉这个问题吗?