【Unity】打字机效果
发表于2017-08-24
下面给大家介绍的是使用Unity开发实现打字机效果。主要是插入NGUI,利用UGUI的Text来生写打字机效果,一起来看吧。
- using UnityEngine;
- using System.Collections;
- public class ShowFont : MonoBehaviour
- {
- private float ShowTime = 0.2f;
- private int count = 0;
- private UILabel font;
- private string str = " 二十年前,东方未名推辞掌门之后,便离开逍遥谷,云游四海,纵身于山水之间,寄情于花鸟之闲。然而他的足迹遍布各地,而所到之处总会留下许多他的传闻。 东方未明于二十年后重返逍遥谷.";
- // Use this for initialization
- void Start ()
- {
- font = GameObject.Find ("Font").GetComponent
(); - }
- // Update is called once per frame
- void Update ()
- {
- if (count == str.Length - 1) {
- Application.LoadLevel (2);
- }
- ShowTime -= Time.deltaTime;
- if (ShowTime <= 0 && count <= str.Length - 1) {
- font.text = str [count ];
- ShowTime = 0.2f;
- }
- }
- }