先上效果图预览。

============================开始写实现方法================================

1.我用的是UGUI,先在空场景中新建Slider和text组件,拖放到适当位置上

2.然后新建脚本,代码如下

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Aegis : MonoBehaviour
{
/// <summary>
/// 进度条下方显示的文本
/// </summary>
[SerializeField]
Text Aegis_text;
/// <summary>
/// 进度条
/// </summary>
[SerializeField]
Slider slider;
/// <summary>
/// 文字后方点数显示
/// </summary>
float pointCount;
/// <summary>
/// 当前进度
/// </summary>
float progress = 0;
/// <summary>
/// 进度条读取完成时间
/// </summary>
float total_time = 3f;
/// <summary>
/// 计时器
/// </summary>
float time = 0;
void OnEnable()
{
//开启协程
StartCoroutine("AegisAnimation");
}
void Update()
{
//记录时间增量
time += Time.deltaTime;
//当前进度随着时间改变的百分比
progress = time / total_time;
if (progress >= 1)
{
return;
}
//把进度赋给进度条的值
slider.value = progress;
}
void OnDisable()
{
//关闭协程
StopCoroutine("AegisAnimation");
}
/// <summary>
/// 检测外挂协程
/// </summary>
/// <returns></returns>
IEnumerator AegisAnimation()
{//检测外挂...... 防外挂机制启动...... 启动成功...... 安全游戏......

while (true)
{
yield return new WaitForSeconds(0.1f);
float f = slider.value;
//设置进度条的value值在某个区间的时候要显示的字符串
string reminder = "";
if (f < 0.25f)
{
reminder = "检测外挂";
}
else if (f < 0.5f)
{
reminder = "启动防外挂机制";
}
else if (f < 0.75f)
{
reminder = "启动成功";
}
else
{
reminder = "进入游戏";
}
//显示字符串后面的“.”
pointCount++;
if (pointCount == 7)
{
pointCount = 0;
}
for (int i = 0; i < pointCount; i++)
{
reminder += ".";
}
//把显示内容赋给场景中的text
Aegis_text.text = reminder;
}
}
}

3.把写好的脚本拖给任意游戏物体上,我放在了Canvas上,把脚本中需要的游戏物体进行赋值。

这时候基本就完成了,可以运行看下效果。

PS:需要注意的是必须做第三步,否则程序会报空引用

如果要写协程的话,一定要记得调用协程,否则协程不会执行,调用方式为StartCoroutine("协程名称");

Unity协程实现伪加载页面的更多相关文章

  1. unity协程coroutine浅析

    转载请标明出处:http://www.cnblogs.com/zblade/ 一.序言 在unity的游戏开发中,对于异步操作,有一个避免不了的操作: 协程,以前一直理解的懵懵懂懂,最近认真充电了一下 ...

  2. Unity协程(Coroutine)原理深入剖析

    Unity协程(Coroutine)原理深入剖析 By D.S.Qiu 尊重他人的劳动,支持原创,转载请注明出处:http.dsqiu.iteye.com 其实协程并没有那么复杂,网上很多地方都说是多 ...

  3. Unity协程(Coroutine)原理深入剖析(转载)

    记得去年6月份刚开始实习的时候,当时要我写网络层的结构,用到了协程,当时有点懵,完全不知道Unity协程的执行机制是怎么样的,只是知道函数的返回值是IEnumerator类型,函数中使用yield r ...

  4. 【转】Unity协程(Coroutine)原理深入剖析

    Unity协程(Coroutine)原理深入剖析 By D.S.Qiu 尊重他人的劳动,支持原创,转载请注明出处:http.dsqiu.iteye.com 记得去年6月份刚开始实习的时候,当时要我写网 ...

  5. 聊一聊Unity协程背后的实现原理

    Unity开发不可避免的要用到协程(Coroutine),协程同步代码做异步任务的特性使程序员摆脱了曾经异步操作加回调的编码方式,使代码逻辑更加连贯易读.然而在惊讶于协程的好用与神奇的同时,因为不清楚 ...

  6. webclient 比浏览器加载页面慢的一个问题

    测试中发现webclient 比浏览器加载页面慢的一个问题:原因WebClient 支持 gzip, deflate,但是未设置 解决方案: class WebClientEx : WebClient ...

  7. Unity协程(Coroutine)管理类——TaskManager工具分享

    博客分类: Unity3D插件学习,工具分享 源码分析   Unity协程(Coroutine)管理类——TaskManager工具分享 By D.S.Qiu 尊重他人的劳动,支持原创,转载请注明出处 ...

  8. RadioGroup+Fragment 使用Fragment的add()方法,防止使用replace每次都重新加载页面,造成资源浪费

    radiogroup+fragment是很常用的主页导航控件,之前为了代码简便一直使用的replace()替换fragment,代码如下: getSupportFragmentManager().be ...

  9. jquery加载页面的方法

    jquery加载页面的方法(页面加载完成就执行),建议大家看下windows.onload与$(document).ready之间的区别.   1.$(function(){ $("#a&q ...

随机推荐

  1. AOP之proceedingjoinpoint和joinpoint区别(获取各对象备忘)、动态代理机制及获取原理代理对象、获取Mybatis Mapper接口原始对象

    现在AOP的场景越来越多,所以我们有必要理解下和AOP相关的一些概念和机制. import org.aspectj.lang.reflect.SourceLocation; public interf ...

  2. 直方图均衡化与Matlab代码实现

    昨天说了,今天要好好的来解释说明一下直方图均衡化.并且通过不调用histeq函数来实现直方图的均衡化. 一.直方图均衡化概述 直方图均衡化(Histogram Equalization) 又称直方图平 ...

  3. SAP如何修改表的数据

     修改表: 事务代码:se16n  输入表名字   输入 /h 进入维护模式  修改 GD-EDIT 和 GD-SAPEDIT  内容为大写X.                          se ...

  4. Javascript的千分位和去除千分位

    1.转成千分位,保留两位 comdify(n) { let num = Number(n); let re = /\d{1,3}(?=(\d{3})+$)/g; let n1 = num.toFixe ...

  5. 【新特性】JDK1.7

    一.switch中可以使用字串 String s = "test";switch (s) { case "test" :   System.out.printl ...

  6. 论文笔记:Decoders Matter for Semantic Segmentation: Data-Dependent Decoding Enables Flexible Feature Aggregation

    Decoders Matter for Semantic Segmentation: Data-Dependent Decoding Enables Flexible Feature Aggregat ...

  7. HDU 3948 The Number of Palindromes(Manacher+后缀数组)

    题意 求一个字符串中本质不同的回文子串的个数. $ 1\leq |string| \leq 100000$ 思路 好像是回文自动机的裸题,但是可以用 \(\text{Manacher}\) (马拉车) ...

  8. SonarQube 中文教程 (1)- 简介

    SonarQube是什么 SonarQube 是一个用于代码质量管理的开源平台,用于管理源代码的质量. 通过插件形式,可以支持包括 java, C#, C/C++, PL/SQL, Cobol, Ja ...

  9. Pandorabox(Openwrt) 双宽带(WAN) 叠加网络实战

    准备 一台已经刷好Pandorabox(Openwrt)的路由器.两条宽带 实战环境 固件:PandoraBox R8.1.12 By Lean 硬件:K2P A1版 过程 配置VLAN 为了将一个L ...

  10. IBase<T>

    public interface IBase<T>//基类 { IEnumerable<T> SelectAll();//查询所有 T FindById(int ID);//根 ...