Health/Assets/_VoiceAssistant/Scripts/Animations/Anim_SequenceFrame.cs

66 lines
1.3 KiB
C#
Raw Normal View History

2023-11-21 08:57:37 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Anim_SequenceFrame : MonoBehaviour
{
public Material material;
public int rowNum,//<2F><>
columnNum;//<2F><>
public float fps = 2;
float timer = 0;
int currentIndex = 0;
float xSize, ySize;
int texId = Shader.PropertyToID("_MainTex");
private void Awake()
{
var r = GetComponent<Renderer>();
if (r)
{
material = r.material;
}
else
{
var g = GetComponent<Graphic>();
if (g)
material = g.material;
}
ySize = 1f / rowNum;
xSize = 1f / columnNum;
material.SetTextureScale(texId, new Vector2(xSize, ySize));
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float time = 1 / fps;
timer += Time.deltaTime;
if(timer >= time)
{
currentIndex += 1;
currentIndex %= rowNum * columnNum;
timer -= time;
}
int row = currentIndex % columnNum;
int column = currentIndex % rowNum;
material.SetTextureOffset(texId, new Vector2((column - 1) * xSize, (row - 1) * ySize));
}
}