Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
SpriteAnimation.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3
4[RequireComponent(typeof(SpriteRenderer))]
5public class SpriteAnimation : MonoBehaviour
6{
7 [Serializable]
8 public class Item
9 {
10 public Sprite sprite;
11
12 public Vector3 pos;
13
14 public float angle;
15
16 public float angleRange;
17 }
18
19 public Item[] items;
20
21 public float minInterval;
22
23 public float maxInterval;
24
25 public bool randomAngle;
26
27 public Transform link;
28
29 private SpriteRenderer sr;
30
31 private int index;
32
33 private float _baseAngle;
34
35 private float interval;
36
37 private void Awake()
38 {
39 sr = GetComponent<SpriteRenderer>();
40 sr.sprite = items[0].sprite;
41 interval = UnityEngine.Random.Range(minInterval, maxInterval);
42 if (randomAngle)
43 {
44 _baseAngle = UnityEngine.Random.Range(0, 360);
45 }
46 InvokeRepeating("Refresh", 0f, interval);
47 }
48
49 private void Refresh()
50 {
51 index++;
52 if (index >= items.Length)
53 {
54 index = 0;
55 }
57 sr.sprite = item.sprite;
58 if ((bool)link)
59 {
60 link.localPosition = item.pos;
61 link.localEulerAngles = new Vector3(0f, 0f, _baseAngle + item.angle + UnityEngine.Random.Range(0f - item.angleRange, item.angleRange));
62 }
63 }
64}
SpriteRenderer sr