Cute_demon_attacks/meng_yao/Assets/communal/UI/SpriteAniation.cs

48 lines
1007 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//one sprites
public class SpriteAniation : MonoBehaviour
{
[Header("帧动画的图")]
public List<Sprite> sprites=new List<Sprite>();
[Header("播放动画的image")]
public Image image;
[Header("帧时间,单位毫秒默认100")]
public float Aintime=100f;
private int index=0;
// Start is called before the first frame update
void Start()
{
if (image==null)
{
Debug.LogError("image is null");
}
if (sprites.Count==0)
{
Debug.LogError("sprites is not");
}
InvokeRepeating("ainstart",0f,(Aintime / 1000));
}
void ainstart()
{
image.overrideSprite = sprites[index];
index++;
if (index> sprites.Count-1)
{
index = 0;
}
}
private void OnDestroy()
{
sprites = null;
}
}