【Unity】打字机效果

发表于2017-08-24
评论0 1.6k浏览

下面给大家介绍的是使用Unity开发实现打字机效果。主要是插入NGUI,利用UGUI的Text来生写打字机效果,一起来看吧。

 cop
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class ShowFont : MonoBehaviour  
  5. {  
  6.     private  float ShowTime = 0.2f;  
  7.     private int count = 0;  
  8.     private UILabel font;  
  9.     private string str = "     二十年前,东方未名推辞掌门之后,便离开逍遥谷,云游四海,纵身于山水之间,寄情于花鸟之闲。然而他的足迹遍布各地,而所到之处总会留下许多他的传闻。 东方未明于二十年后重返逍遥谷.";  
  10.     // Use this for initialization  
  11.     void Start ()  
  12.     {  
  13.         font = GameObject.Find ("Font").GetComponent ();  
  14.     }  
  15.   
  16.     // Update is called once per frame  
  17.     void Update ()  
  18.     {  
  19.         if (count == str.Length - 1) {  
  20.             Application.LoadLevel (2);  
  21.         }  
  22.         ShowTime -= Time.deltaTime;  
  23.         if (ShowTime <= 0 && count <= str.Length - 1) {  
  24.             font.text  = str [count ];  
  25.             ShowTime = 0.2f;  
  26.         }  
  27.     }  
  28. }  

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引

标签: