时间管理,设定时间切换两段动画。要开始动画时,只要把xiFlag或者huFlag,任意一个设置为true,就能自动运行。都为false为不执行
using UnityEngine;
using System.Collections;
public class HuXi : MonoBehaviour {
<span style="white-space:pre"> </span>public GameObject hu = null; //呼气动画
public GameObject xi = null; //吸气动画
public float huTime = 2.0f; //呼气时间
public float xiTime = 2.0f; //吸气时间
private float interval = 0; //间隔时间
private float lastTime = 0; //只是用于保存上一次执行的时间
private bool huFlag = false;
private bool xiFlag = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
interval = Time.time - lastTime;
if (xiFlag) {
xi.SetActive (true);
hu.SetActive (false);
if (interval > huTime) {
//print (interval);
lastTime = Time.time;
hu = !hu;
xi = !xi;
}
} else if (huFlag) {
xi.SetActive (false);
hu.SetActive (true);
if (interval > xiTime) {
//print (interval);
lastTime = Time.time;
hu = !hu;
xi = !xi;
}
}
}
}