当前位置:网站首页>Unity 引导系统.点击目标物体后提示文字变色进入下一步
Unity 引导系统.点击目标物体后提示文字变色进入下一步
2022-07-29 09:18:00 【饿掉鱼】
using HighlightingSystem;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/*
* 脚本使用文字颜色来判断目标是否达成
* 格式固定两行
*
*/
public class Test : MonoBehaviour
{
[Tooltip("录音")]
public Button RecodePen;
//切换开关的旋转状态
public int _SwitchChangerStep;
[Header("这里是需要变色的文字")]
public Text text1, text2;
#region 提示栏文字列表
static string[] t1 = new string[] {
"点击录音按钮",
"点击录音按钮",
"点击录音按钮"
};
static string[] t2 = new string[]
{
"点击A",
"点击B",
"点击C"
};
[Header("需要点击的目标物体")]
public GameObject[] TargetGameobject = new GameObject[t1.Length];
#endregion
public int step;
[Header("录音按钮")]
public Button RecodeSubmit;//这个当时做项目要每个环节都有个录音.做其他需求时可以去掉这个
private void OnEnable()
{
TargetGameobject[step].SetActive(true);
Debug.Log(string.Format("<color=yellow>{0}</color>", $"{System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName}脚本启动") + "\n此脚本检测目标");
RecodeSubmit.onClick.AddListener(() => {
RecodePen.interactable = false;
text1.color = Color.green;
});
}
private void Awake()
{
if (t1.Length != t2.Length) Debug.LogError("文字未能一一对应!"); //初始化
text1.color = Color.white;
text2.color = Color.white;
}
void Update()
{
if (step < t1.Length)
{
text1.text = t1[step];
text2.text = t2[step];
}
else
{
text1.text = null; text2.text = null;
enabled = false;//此脚本的工作结束了,初始化
}
if (text1.color == Color.green && text2.color == Color.green)
{
text1.color = Color.white; text2.color = Color.white; RecodePen.interactable = true;
step++;
TargetGameobject[step].SetActive(true);
RecodeSubmit.onClick.AddListener(() => {
text1.color = Color.green;
});
}
//目标体检测,文字变色
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit raycastHit;
Physics.Raycast(ray, out raycastHit, 2000);
Debug.Log(raycastHit.transform.name);
//当时是用高亮来确认目标物体的
//如果不加高亮,就对应Targetgameobject[]去
if (raycastHit.transform.gameObject.activeInHierarchy && raycastHit.transform.gameObject.GetComponent<Highlighter>().enabled)
{
raycastHit.transform.gameObject.SetActive(false);
text2.color = Color.green;
}
}
}
}
实现效果:

边栏推荐
- 数据表示与计算(进制)
- Reptile practice (10): send daily news
- Asp graduation project - based on C # +asp Design and implementation of enterprise investment value analysis system based on. Net + sqlserver (graduation thesis + program source code) -- enterprise in
- Axurerp prototype design starts quickly
- mysql怎么换成中文
- 【BERT-多标签文本分类实战】之一——实战项目总览
- [machine learning] naive Bayesian code practice
- The gold content of PMP certificate has been increased again and included in the scope of Beijing work residence permit
- Excellent package volume optimization tutorial
- Gutcloud technology restcloud completed the pre-A round of financing of tens of millions of yuan
猜你喜欢

Parameter initialization

VS2015采用loadlibrary方式调用dll库

Gutcloud technology restcloud completed the pre-A round of financing of tens of millions of yuan

Demonstration and solution of dirty reading, unrepeatable reading and unreal reading

Mathematical modeling - Differential Equations

2022 electrician (elementary) test question simulation test platform operation

Tesseract text recognition -- simple

Flowable 基础篇1

Floweable foundation Chapter 1

LeetCode刷题(6)
随机推荐
Notes on network principles (five layer network)
基于C语言实现的NFA确定化和DFA最小化
C# 使用数据库对ListView控件数据绑定
2022电工(初级)考题模拟考试平台操作
Leetcode: interview question 08.14. Boolean operation
[Bert multi label text classification practice] I - overview of practical projects
网络原理笔记(五层网络)
Sublime text create page
Trie树(字典树)讲解
Flowable 基础篇2
Flowable UI制作流程图
文件重命名后,怎样将新旧文件名及所在位置导出到excel
[C language] DataGridView binding data
I don't know how lucky the boy who randomly typed logs is. There must be a lot of overtime
2022 electrician (elementary) test question simulation test platform operation
Introduction to translation professional qualification (level) examination
用户身份标识与账号体系实践
2022危险化学品经营单位主要负责人操作证考试题库及答案
Flowable 基础篇1
mysql将部分表名统一转换为大写