CQ_Intelligent-Technology-T.../Assets/Scripts/语音控制脚本/PlayImage.cs

55 lines
1.3 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayImage : MonoBehaviour
{
public static PlayImage Instance;
public Sprite[] sprites; // 存储序列帧动画的所有帧
public float framesPerSecond = 10.0f; // 每秒播放的帧数
private float index = 0;
private int imageindex = 0;
public Image image;
bool isPlay = false;
// Start is called before the first frame update
private void Update()
{
if (isPlay)
{
index += 0.3f;
if (index >= framesPerSecond)
{
imageindex++;
index = 0;
if (imageindex >= sprites.Length)
{
imageindex = 0;
}
image.sprite = sprites[imageindex];
}
}
else
{
image.sprite = sprites[0];
}
}
public void PlayImager()
{
isPlay = !isPlay;
}
IEnumerator PlaySprites(bool isPlay)
{
while (isPlay)
{
for (int i = 0; i < sprites.Length; i++)
{
image.sprite = sprites[i];
yield return new WaitForSeconds(1f / framesPerSecond);
}
}
}
}