在使用按钮做组合框时,我突然想到了,是否可以制作类似:“想要更多?好的。按下并得到它:)”例如,我有一个带有水果、蔬菜、浆果的组合框。因此,我选择了水果、蔬菜、浆果,并且我想重复相同的组合框,其中包含水果、蔬菜、浆果的列表。可能我可能需要“添加新水果、蔬菜、浆果”之类的东西。所以我的问题是:是否可以“添加新的水果、蔬菜、浆果”,如果可以,请提供一些反馈:D 问候,蒂姆
这是一个代码示例代码:
using UnityEngine;
using System.Collections;
public class hibye: MonoBehaviour
{
public string slectedItem = "None";
private bool editing = false;
public string slectedItem2 = "None";
private bool editing2 = false;
public string slectedItem3 = "None";
private bool editing3 = false;
private void OnGUI()
{
if ( GUILayout.Button(slectedItem))
{
editing = true;
}
if (editing)
{
string[] sig = {"Banana","Apple","Orange"};
for (int x = 0; x < sig.Length ; x++)
{
if (GUILayout.Button(sig[x]))
{
slectedItem = sig[x];
editing = false;
}
}
}
if ( GUILayout.Button(slectedItem2))
{
editing2 = true;
}
if (editing2)
{
string[] sig = {"Cabbage","Potato","Paprika"};
for (int x = 0; x < sig.Length ; x++)
{
if (GUILayout.Button(sig[x]))
{
slectedItem2 = sig[x];
editing2 = false;
}
}
}
if ( GUILayout.Button(slectedItem3))
{
editing3 = true;
}
if (editing3)
{
string[] sig = {"Baneberry","Blackberry","Grape"};
for (int x = 0; x < sig.Length ; x++)
{
if (GUILayout.Button(sig[x]))
{
slectedItem3 = sig[x];
editing3 = false;
}
}
}
}
}
我想让代码最短并添加另一个 GUILayout.Button,它允许我再次选择现有项目而不更改现有选择的项目。