unity3d - Unity-如何在一个对话树脚本上创建两个Button事件
问题描述
所以我一直在用一个简单的对话树组合一个测试程序,在那里你会得到一个问题和两个选项按钮,当你按下一个按钮时,你会进入树的另一个层次。所以我做了一个列表,添加了所有的树级别,包含问题的参数和两个选项。不过,我让自己感到困惑。如果我按下某个按钮,我不确定如何将级别添加到列表中。除了初始化脚本之外,我想保留一个脚本。我能想到的最好的方法是为按下按钮创建布尔函数,但我真的想不出如何区分一个按钮和另一个按钮。如果有人对如何解决这个问题有任何更好的想法。我会很感激。谢谢你。
public class Level : MonoBehaviour {
bool button1Pressed;
bool button2Pressed;
private void Start()
{
Level Level1 = new Level("Hello", "Hi", "Shut Up");
Level leaf1 = new Level("Don't be Rude");
Level Level2 = new Level("What you Doing?", "Not Much", "None of your Business");
Level leaf2 = new Level("Well Excuuuuse Me");
Level Level3 = new Level("Can I do that too?", "Sure", "Go Away");
Level leaf3 = new Level("Fine. Be a Jerk");
Level Level4 = new Level("This is boring, can we do something else?", "Why not?", "You're boring");
Level leaf4 = new Level("I'll go be boring somewhere else");
Level Level5 = new Level("You want ice cream?", "Sounds Good", "I'm allergic");
Level leaf5 = new Level("ok.......");
Level leaf = new Level("I Want Chocolate");
Level1.add(Level1);
Level1.add(leaf1);
Level2.add(Level3);
Level2.add(leaf2);
Level3.add(Level4);
Level3.add(leaf3);
Level4.add(Level5);
Level4.add(leaf4);
Level5.add(leaf5);
Level5.add(leaf);
levels.Add(Level1);
levels.Add(Level2);
levels.Add(Level3);
levels.Add(Level4);
levels.Add(Level5);
}
public static Text Textbox;
public static Button Button1;
public static Button Button2;
public string OptionA;
public string OptionB;
public string Question;
public string Leaf;
private List<Level> levels;
public Level(string question, string optionA, string optionB)
{
this.Question = question;
this.OptionA = optionA;
this.OptionB = optionB;
Textbox.text = Question;
Button1.GetComponentInChildren<Text>().text = OptionA;
Button2.GetComponentInChildren<Text>().text = OptionB;
levels = new List<Level>();
}
public Level(string leaf)
{
this.Leaf = leaf;
Textbox.text = leaf;
}
public void add(Level lvl)
{
levels.Add(lvl);
}
public List<Level> getLevels()
{
return levels;
}
void OnPointerDown()
{
button1Pressed = true;
}
void OnPointerUp()
{
button1Pressed = false;
}
}
初始化器
public class Initializer : MonoBehaviour {
public Text Textbox;
public Button Button1;
public Button Button2;
void Awake()
{
Level.Textbox = this.Textbox;
Level.Button1 = this.Button1;
Level.Button2 = this.Button2;
}
}
解决方案
推荐阅读
- gremlin - 将 Gremlin 查询结果保存到文件
- c++ - 如何在不使用 strtok() 和 strlen() 函数的情况下编写此代码?
- javascript - Karma 启动和拆卸配置
- azure - Azure App 服务从 HttpClient 返回 502 bad gateway
- php - 从维基百科获取图像 URL
- reactjs - 酶安装()不渲染子组件
- azure - Azure 安全中心更新间隔 - 实际的最后检查日期是什么时候?
- linux - bash 脚本 - 找不到“docker run -it my_image bash”命令
- google-cloud-platform - 我可以在 GCP 中创建一个 VPN 来提供对多个项目的访问吗?
- firebase - 获取符合存储规则的 Firebase Cloud Storage 的客户端 URL