【Unity】Unity用图片数组播放动画

来源:互联网 发布:剑网三李白捏脸数据 编辑:程序博客网 时间:2024/05/18 17:04
using UnityEngine;using System.Collections;using UnityEngine.UI;public class ImageGroup : MonoBehaviour{public Sprite[] mySprites;Toggle myToggle;Image myImage;int index = 0;float waitTime = 0f;void Start (){myToggle = gameObject.GetComponent<Toggle> ();myImage = gameObject.transform.GetChild (0).GetComponent<Image> ();}// Update is called once per framevoid Update (){if (myToggle.isOn) {StartCoroutine (ChangeImage (waitTime));waitTime += 0.2f;} else {StopAllCoroutines ();myImage.sprite = mySprites [0];index = 0;waitTime = 0f;}}IEnumerator ChangeImage (float myTime){Debug.Log(myTime);yield return new WaitForSeconds (myTime);index++;if (index < mySprites.Length) {myImage.sprite = mySprites [index];}}}

1 0
原创粉丝点击