唐寅背景

在这里插入图片描述

using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; public class UIContraller : MonoBehaviour { // Start is called before the first frame update //创建列表来存物体 //以类似数组的形式来存取 List<GameObject> panels= new List<GameObject>(); List<GameObject> buttons= new List<GameObject>(); string s = "";//存文字 int num = 0; float t = 0; bool isPrint=false; bool isFirst=true; int currentIndex = 0;//当前值 VideoPlayer videoPlayer; private GameObject selectionPanel;//答题界面 string[] ss = { "1.清明上河图描绘的是什么风光?#A.临安|B.汴梁|C.长安|D.江宁府#B", "2.下面不属于十大名画的是?#A.《富春山居图》|B.《清明上河图》|C.《洛神赋》|D.《百花图》#D", "3.《富春山居图》的作者是谁?#A.李白|B.唐寅|C.徐悲鸿|D.黄公望#D", "4.《清明上河图》的作者是谁?#A.张择端|B.唐寅|C.徐悲鸿|D.黄公望#A", "5.《富春山居图》的哪个朝代的画作?#A.唐|B.宋|C.元|D.明#C" }; string[] 题目 = new string[5]; string[] 选项 = new string[5]; string[] 答案 = new string[5]; int indexQuestion; Toggle[] toggles = new Toggle[4]; Dictionary<int,string> dic = new Dictionary<int,string>(); string answer = ""; int score = 0; public Text scoretext; public GameObject resultPanel; void Start() { dic.Add(0, "A"); dic.Add(1, "B"); dic.Add(2, "C"); dic.Add(3, "D"); for (int i = 0; i < 10; i++) { //全局查找,可以找失活的物体 panels.Add(transform.Find("Image3" + i).gameObject); buttons.Add(transform.Find("buTTon3" + i).gameObject); panels[i].SetActive(false); } selectionPanel=transform.Find("Showselection").gameObject; for (int i = 0; i < ss.Length; i++) { string[] sss=ss[i].Split('#'); 题目[i] = sss[0]; 选项[i] = sss[1]; 答案[i] = sss[2]; } selectionPanel.transform.Find("题目").GetComponent<Text>().text = 题目[indexQuestion]; for (int i = 0;i < 4; i++) { selectionPanel.transform.GetChild(2).GetChild(i).GetChild(1).GetComponent<Text>().text = 选项[indexQuestion].Split('|')[i]; } for (int i = 0; i < 4; i++) { selectionPanel.transform.GetChild(2).GetChild(i).GetComponent<Toggle>(); } for (int i = 0; i < 4; i++) { toggles[i] = selectionPanel.transform.GetChild(2).GetChild(i).GetComponent<Toggle>(); } } public void NextQuestion() { Getanswer(); indexQuestion++; if (indexQuestion == ss.Length) { selectionPanel.SetActive(false); foreach (var item in answer) { print(item); } for (int i = 0; i < answer.Length; i++) { if (answer[i].ToString() == 答案[i]) { score += 20; } } if (resultPanel != null) { resultPanel.SetActive(true); } if (scoretext != null) { scoretext.text = "您的得分为:" + score; } return; } else if (indexQuestion == ss.Length-1) { selectionPanel.transform.GetChild(3).GetChild(0).GetComponent<Text>().text = "答题完毕"; } selectionPanel.transform.Find("题目").GetComponent<Text>().text = 题目[indexQuestion]; for (int i = 0; i < 4; i++) { selectionPanel.transform.GetChild(2).GetChild(i).GetChild(1).GetComponent<Text>().text = 选项[indexQuestion].Split('|')[i]; } } public void ShowSelectionPanel(bool isShow) { indexQuestion = 0; score = 0; answer = " "; selectionPanel.transform.Find("题目").GetComponent<Text>().text = 题目[indexQuestion]; for (int i = 0; i < 4; i++) { selectionPanel.transform.GetChild(2).GetChild(i).GetChild(1).GetComponent<Text>().text = 选项[indexQuestion].Split('|')[i]; } selectionPanel.transform.GetChild(3).GetChild(0).GetComponent<Text>().text = "下一题"; selectionPanel.SetActive(isShow); } public void Getanswer() { for (int i = 0; i < toggles.Length; i++) { if (toggles[i].isOn) { answer += dic[i]; } } for (int i = 0; i < toggles.Length; i++) { toggles[i].isOn = false; } } public void PlayVideo(bool b) { if (b) { videoPlayer.Play(); } else { videoPlayer.Pause(); } } //image的打开和关闭 public void PanelActive(int index,bool isActive) { panels[index].SetActive(isActive); if (index == 8) { if (isActive) { videoPlayer = GameObject.FindObjectOfType<VideoPlayer>(); } } else { if (isActive) { if (isFirst) { isFirst = false; } else { panels[currentIndex].transform.GetChild(0).GetComponent<Text>().text = s; num = 0; t = 0; } currentIndex = index; //s存文字 s = panels[index].transform.GetChild(0).GetComponent<Text>().text; //清空 panels[index].transform.GetChild(0).GetComponent<Text>().text = ""; isPrint = true; } } } // Update is called once per frame void Update() { //文字打印 if (isPrint) { t += Time.deltaTime; if (t > 0.1f) { t = 0; panels[currentIndex].transform.GetChild(0).GetComponent<Text>().text += s[num]; num++; if (num == s.Length) { isPrint = false; t= 0; num = 0; } } } if (!panels[currentIndex].activeSelf&&!isFirst) { num = 0; t = 0; panels[currentIndex].transform.GetChild(0).GetComponent<Text>().text = s; isPrint = false; } } }如何在这段代码的基础上实现上一题和选择题目答题的功能
12-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值