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; /// /// 录音提示 /// private GameObject tips; bool isPlay = false; bool isClick = true; // Start is called before the first frame update private void Start() { tips = transform.GetChild(1).gameObject; } private void Update() { if (isPlay) { tips.SetActive(true); index += 0.3f; if (index >= framesPerSecond) { imageindex++; index = 0; if (imageindex >= sprites.Length) { imageindex = 0; } image.sprite = sprites[imageindex]; } } else { tips.SetActive(false); image.sprite = sprites[0]; } } public void PlayImager() { isPlay = !isPlay; } public void Show(GameObject gameObject) { isClick = !isClick; StartCoroutine(WaitShow(gameObject, isClick)); } IEnumerator WaitShow(GameObject gameObject, bool isclick) { if (isclick) { yield return new WaitForSeconds(2f); gameObject.SetActive(true); } } }