using UnityEngine; using UnityEngine.UI; public class AnimasiRusa : MonoBehaviour { [Header("Masukkan 106 Frame Rusa ke Sini:")] public Sprite[] daftarFrameRusa; [Header("Setting Kecepatan (Rekomendasi: 0.03 - 0.05):")] public float kecepatanAnimasi = 0.04f; private Image gambarTarget; private int indexSekarang = 0; private float timer = 0f; void Start() { gambarTarget = GetComponent(); // Pastikan gambar pertama langsung muncul if (daftarFrameRusa.Length > 0 && gambarTarget != null) { gambarTarget.sprite = daftarFrameRusa[0]; } } void Update() { // Jaring pengaman biar gak error kalau list kosong if (daftarFrameRusa == null || daftarFrameRusa.Length == 0) return; timer += Time.deltaTime; if (timer >= kecepatanAnimasi) { timer = 0f; // Pindah ke frame berikutnya indexSekarang = (indexSekarang + 1) % daftarFrameRusa.Length; // Cek lagi apakah slot frame ini ada isinya (mencegah Missing/Null) if (daftarFrameRusa[indexSekarang] != null) { gambarTarget.sprite = daftarFrameRusa[indexSekarang]; } } } }