创建动态提示窗口DynamicWnd.cs
编写代码
using UnityEngine;
using UnityEngine.UI;
//功能 : 动态窗口界面
public class DynamicWnd : WindowsRoot{public Animation tipsAni;public Text txtTips;protected override void InitWnd() {base.InitWnd();//在启动时先隐藏提示文本txtTips.gameObject.SetActive(false);}//设置提示内容public void SetTips(string tips) {txtTips.gameObject.SetActive(true);SetText(txtTips, tips);//txtTips.text = tips;}
}
进行关联
运行播放
继续编写 拿到动画单元组件
接着在播放动画单元之后 利用协程延时关闭这个动画单元
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
//功能 : 动态窗口界面
public class DynamicWnd : WindowsRoot{public Animation tipsAni;public Text txtTips;protected override void InitWnd() {base.InitWnd();//在启动时先隐藏提示文本txtTips.gameObject.SetActive(false);}//设置提示内容public void SetTips(string tips) {txtTips.gameObject.SetActive(true);SetText(txtTips, tips);//txtTips.text = tips;//拿到这个动画文件AnimationClip clip = tipsAni.GetClip("DynamicTip");//开始播放tipsAni.Play();//延时关闭激活状态#region 【开启协程】StartCoroutine(AniPlayDone(clip.length, () =>{txtTips.gameObject.SetActive(false);}));#endregion}#region 【协程】延时关闭激活IEnumerator AniPlayDone(float sec, Action cb) {yield return new WaitForSeconds(sec);//回调自己if (cb != null)cb();}#endregion
}
写好了之后在游戏根入口GameRoot.cs中引用动态提示窗口DynamicWnd.cs 并调用设置文本内容
进行关联
运行效果
End.