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)
时间: 2024-02-15 19:11:04 浏览: 76
C#关于System.Collections空间详解
这段代码有两个 `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()` 函数。这样就避免了编译错误。
阅读全文