【发布时间】:2012-01-09 08:59:09
【问题描述】:
我正在尝试使用 GUILayout 按钮(以及开始/结束垂直/水平等)在 Unity 中创建一个菜单,并且我想要它,以便当我单击一个按钮时,某些信息会显示在它的下方。我正在尝试使用此代码:
foreach(agents中的Agent代理)//(EntityManager.FindAll()中的Agent代理) {
//GUILayout.BeginHorizontal();
if (GUILayout.Button(agent.shortName))
{
Debug.Log("clicked" + agent.shortName);
GUILayout.BeginHorizontal();
GUILayout.BeginVertical();
GUILayout.Label("Health: "+agent.Health +"/"+agent.MaximumHealth);
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.BeginVertical();
GUILayout.Label("Thoughts: nothing");
GUILayout.EndVertical();
GUILayout.EndHorizontal();
/*if (agent.hasFlag)
{ //TODO: Add this function to agent
GUILayout.BeginVertical();
GUILayout.Label("Has the flag");
GUILayout.EndVertical();
}*/
}
//GUILayout.EndHorizontal();
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
// Make the windows be draggable.
GUI.DragWindow();
这成功创建了 3 个按钮(因为我在 foreach 循环中使用的代理列表中有 3 个代理)并且按钮工作(这就是添加 Debug.Log 代码的原因)。但是,我添加的所有内容(例如标签)都不会在单击按钮时出现。做我想做的事情的正确方法是什么?
【问题讨论】:
标签: c# user-interface unity3d