变化贴图,类似于幻灯片

来源:互联网 发布:淘宝抢购秒杀神器 编辑:程序博客网 时间:2024/05/16 14:19

//变化贴图,类似于幻灯片
using UnityEngine;
using System.Collections;
public class SwitchbackGroundimage : MonoBehaviour {
//计数器
public Texture[] image;
private int index=0;
//public int number = 3;
private float _time;
private float _endTime;
// Use this for initialization
void Start () {
//开始时刻的时间
   _time = Time.time;
}

// Update is called once per frame
void Update () {
//Debug.Log(Time.time);
  //现在的时间
 _endTime = Time.time;
//开始时刻 到现在的时间差值
 float timeOffset = _endTime- _time;

     if (timeOffset >2) {
if (index <image.Length) {
guiTexture.texture= image[index];
index+=1;

}else {
index = 0;
guiTexture.texture = image[index];
}
   //记下换好下一张图片的时间
_time = Time.time;

}

}
}