void duihua(int aa) { if(aa==0) switch(n) { case 0: Duihuakuang.text = "【序幕】";n++;break ; case 1: Duihuakuang.text = "【漆黑的空间】\n【像是丢进黑暗本身一样虚无......】"; n++; break; case 2: Duihuakuang.text = "【你听见什么声音在脑中突兀地响起】"; n++; break; case 3: Duihuakuang.text = "【?:滋......滋......】"; n++; break; case 4: Duihuakuang.text = "?:...we......*wei......喂?测试,测试......听得见吗?"; Button1_text.text = "回应"; Button2_text.text = "不回应"; Button1.SetActive(true); Button2.SetActive(true); Buttonjixu.SetActive(false); n++;break; default: if (anniu==1) { Duihuakuang.text = "?:呀嘞呀嘞,居然连通了嘛~我还以为这条线路早就弃用了——"; AA = 1; } if(anniu==2) { Duihuakuang.text = "?:喂——有人在吗?哈喽——"; AA = 2; } n=0;break; }
时间: 2024-02-10 11:22:04 浏览: 130
这段代码是一个名为“duihua”的函数,它接受一个整数参数aa作为输入。在函数中,首先进行了一个if判断,如果aa等于0,则执行一个switch语句。
在switch语句中,根据变量n的值执行不同的代码块。n的初值为0,当n等于0时,对话框的文本被设置为“【序幕】”,并将n的值加1。当n等于1时,对话框的文本被设置为“【漆黑的空间】\n【像是丢进黑暗本身一样虚无......】”,并将n的值加1。当n等于2时,对话框的文本被设置为“【你听见什么声音在脑中突兀地响起】”,并将n的值加1。当n等于3时,对话框的文本被设置为“【?:滋......滋......】”,并将n的值加1。
当n等于4时,对话框的文本被设置为“?:...we......*wei......喂?测试,测试......听得见吗?”,并显示了两个按钮,分别是“回应”和“不回应”。同时隐藏了一个名为Buttonjixu的按钮。最后将n的值加1。
当n的值大于等于5时,执行一个if判断。如果按钮的编号anniu等于1,则对话框的文本被设置为“?:呀嘞呀嘞,居然连通了嘛~我还以为这条线路早就弃用了——”,并将变量AA的值设置为1。如果按钮的编号anniu等于2,则对话框的文本被设置为“?:喂——有人在吗?哈喽——”,并将变量AA的值设置为2。最后将n的值设置为0。
这段代码的功能是控制对话框的显示和按钮的交互,用于实现一个对话交互游戏的部分功能。
相关问题
public Jueseshuxing Shuxin; public void Xuanze1_Button() { Button1.SetActive(false); Button2.SetActive(false); Button3.SetActive(false); anniu = 1; Duihua(AA); } public void Xuanze2_Button() { Button1.SetActive(false); Button2.SetActive(false); Button3.SetActive(false); anniu = 2; Duihua(AA); } public void Xuanze3_Button() { Button1.SetActive(false); Button2.SetActive(false); Button3.SetActive(false); anniu = 3; Duihua(AA); } public void Continue_Button() { Duihua(AA); } void duihua(int aa) { if (aa == 0) switch (n) { case 0: Duihuakuang.text = "【序幕】"; n++; break; case 1: Duihuakuang.text = "【漆黑的空间】\n【像是坠入了深渊般虚无与空洞......浓浓的窒息感】"; n++; break; case 2: Duihuakuang.text = "【脑海中不断地响起....阵阵刺耳的声鸣。】"; n++; break; case 3: Duihuakuang.text = "【α:滋....¥!@#%#!¥?滋%.....】"; n++; break; case 4: Duihuakuang.text = "【α:...你...醒了吗?】"; Button1_text.text = "【嗯.】"; Button2_text.text = "【......】"; Button3_text.text = "【你是谁?】" Button1.SetActive(true); Button2.SetActive(true); Button3.SetActive(true); Buttonjixu.SetActive(false); n++; break; default: if (anniu == 1) { Duihuakuang.text = "【α:呵呵,我还以为你会选择沉默~】"; AA = 1; } if (anniu == 2) { Duihuakuang.text = "【α:...这样呀~】"; AA = 2; } if (anniu == 3) { Duihuakuang.text = "【α:我是...呵,你不必知道.】"; AA = 3; } n = 0; break; } }
您提供的代码存在一些语法错误,可能是因为缺少一些分号或者括号不匹配。下面是修改后的代码:
```
public Jueseshuxing Shuxin;
public void Xuanze1_Button()
{
Button1.SetActive(false);
Button2.SetActive(false);
Button3.SetActive(false);
anniu = 1;
Duihua(AA);
}
public void Xuanze2_Button()
{
Button1.SetActive(false);
Button2.SetActive(false);
Button3.SetActive(false);
anniu = 2;
Duihua(AA);
}
public void Xuanze3_Button()
{
Button1.SetActive(false);
Button2.SetActive(false);
Button3.SetActive(false);
anniu = 3;
Duihua(AA);
}
public void Continue_Button()
{
Duihua(AA);
}
void duihua(int aa)
{
if (aa == 0)
switch (n)
{
case 0:
Duihuakuang.text = "【序幕】";
n++;
break;
case 1:
Duihuakuang.text = "【漆黑的空间】\n【像是坠入了深渊般虚无与空洞......浓浓的窒息感】";
n++;
break;
case 2:
Duihuakuang.text = "【脑海中不断地响起....阵阵刺耳的声鸣。】";
n++;
break;
case 3:
Duihuakuang.text = "【α:滋....¥!@#%#!¥?滋%.....】";
n++;
break;
case 4:
Duihuakuang.text = "【α:...你...醒了吗?】";
Button1_text.text = "【嗯.】";
Button2_text.text = "【......】";
Button3_text.text = "【你是谁?】";
Button1.SetActive(true);
Button2.SetActive(true);
Button3.SetActive(true);
Buttonjixu.SetActive(false);
n++;
break;
default:
if (anniu == 1)
{
Duihuakuang.text = "【α:呵呵,我还以为你会选择沉默~】";
AA = 1;
}
if (anniu == 2)
{
Duihuakuang.text = "【α:...这样呀~】";
AA = 2;
}
if (anniu == 3)
{
Duihuakuang.text = "【α:我是...呵,你不必知道.】";
AA = 3;
}
n = 0;
break;
}
}
```
请注意,我只是修改了语法错误,但是代码的逻辑仍然需要您自己检查和修改。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Duihua : MonoBehaviour { public Text Duihuakuang;//对话框文本 void Start() { Duihuakuang = GetComponent<Text>(); } public Text Button1_text; public Text Button2_text; public Text Button3_text; void Start() { Button3 = GameObject.Find("Button3"); Button3_text = Button3.GetComponentInChildren<Text>(); } void updateButton3Text(string newText) { Button3_text.text = newText; } public GameObject Button1; public GameObject Button2; public GameObject Button3; public GameObject Buttonjixu; public GameObject shurukuang;//输入框显示 public InputField shuru_text;//输入框文 public GameObject LiHui;//立绘底板 public Sprite Sanjiao;//两个图片 public Sprite Lutou; public int AA = 0;//大进度 public int n = 0;//小进度 public int anniu = 0;//按钮选项 public Jueseshuxing Shuxin; public void Xuanze1_Button() { Button1.SetActive(false); Button2.SetActive(false); Button3.SetActive(false); Buttonjixu.SetActive(true); anniu = 1; duihua(AA); } public void Xuanze2_Button() { Button1.SetActive(false); Button2.SetActive(false); Button3.SetActive(false); Buttonjixu.SetActive(true); anniu = 2; duihua(AA); } public void Xuanze3_Button() { Button1.SetActive(false); Button2.SetActive(false); Button3.SetActive(false); Buttonjixu.SetActive(true); anniu = 3; duihua(AA); } public void Continue_Button() { duihua(AA); } void duihua(int aa)
这段代码有两个 `Start()` 函数,这会导致编译错误。你需要将它们合并成一个函数。你可以将第二个 `Start()` 函数中的内容移动到第一个 `Start()` 函数中,像这样:
```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Duihua : MonoBehaviour
{
public Text Duihuakuang;//对话框文本
public Text Button1_text;
public Text Button2_text;
public Text Button3_text;
public GameObject Button1;
public GameObject Button2;
public GameObject Button3;
public GameObject Buttonjixu;
public GameObject shurukuang;//输入框显示
public InputField shuru_text;//输入框文
public GameObject LiHui;//立绘底板
public Sprite Sanjiao;//两个图片
public Sprite Lutou;
public int AA = 0;//大进度
public int n = 0;//小进度
public int anniu = 0;//按钮选项
public Jueseshuxing Shuxin;
void Start()
{
Duihuakuang = GetComponent<Text>();
Button3 = GameObject.Find("Button3");
Button3_text = Button3.GetComponentInChildren<Text>();
}
void updateButton3Text(string newText)
{
Button3_text.text = newText;
}
public void Xuanze1_Button()
{
Button1.SetActive(false);
Button2.SetActive(false);
Button3.SetActive(false);
Buttonjixu.SetActive(true);
anniu = 1;
duihua(AA);
}
public void Xuanze2_Button()
{
Button1.SetActive(false);
Button2.SetActive(false);
Button3.SetActive(false);
Buttonjixu.SetActive(true);
anniu = 2;
duihua(AA);
}
public void Xuanze3_Button()
{
Button1.SetActive(false);
Button2.SetActive(false);
Button3.SetActive(false);
Buttonjixu.SetActive(true);
anniu = 3;
duihua(AA);
}
public void Continue_Button()
{
duihua(AA);
}
void duihua(int aa)
{
// TODO: 实现对话逻辑
}
}
```
在这个例子中,我们将第二个 `Start()` 函数中的内容移动到了第一个 `Start()` 函数中,同时保留了第二个函数中的 `updateButton3Text()` 函数。这样就避免了编译错误。
阅读全文