You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
using DG.Tweening; |
|
using TMPro; |
|
using UnityEngine; |
|
using Random = UnityEngine.Random; |
|
|
|
namespace Utils |
|
{ |
|
public class FlyingText : MonoBehaviour |
|
{ |
|
public enum State |
|
{ |
|
Normal, |
|
Danger, |
|
Heal |
|
} |
|
|
|
[SerializeField] private TextMeshPro _text; |
|
[SerializeField] private Color _normal; |
|
[SerializeField] private Color _danger; |
|
[SerializeField] private Color _heal; |
|
[SerializeField] private FlyingText _flyingText; |
|
|
|
private static FlyingText Flying { get; set; } |
|
|
|
private void OnEnable() |
|
{ |
|
if(_flyingText != null) |
|
Flying = _flyingText; |
|
} |
|
|
|
public static void Init(int data, State state, Vector3 position) |
|
{ |
|
Init(data > 0 ? string.Format("+{0}", data) : data.ToString(), state, position, Color.black); |
|
} |
|
|
|
public static void Init(string data, State state, Vector3 position, Color color) |
|
{ |
|
var obj = Instantiate(Flying); |
|
var random = (Vector3)Random.insideUnitCircle; |
|
random.z = random.y; |
|
random.y = 0; |
|
obj.transform.position = position + random; |
|
obj._text.text = data; |
|
obj._text.color = color == Color.black ? state == State.Normal ? obj._normal : state == State.Danger ? obj._danger : obj._heal : color; |
|
obj._text.transform.DOMoveY(5f, 1f); |
|
obj._text.DOFade(0f, 1f).OnComplete(() => { Destroy(obj.gameObject); }); |
|
} |
|
} |
|
}
|
|
|