12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using UnityEngine;
- using System.Collections;
- using TMPro;
- [RequireComponent(typeof(PoolObject))]
- public class TextAnnouncement : MonoBehaviour
- {
- public float spinColorSpeed = 0;
- public Color startSpinColor = Color.red;
- public float introTime = 0.5f;
- public float stayTime = 0.5f;
- public float outroTime = 0.25f;
- public float upSpeed = 5;
- PoolObject _poolObject;
- TextMeshProUGUI _label;
- Vector3 _originalScale;
- HSBColor hsbColor;
- void Awake()
- {
- _originalScale = transform.localScale;
- _poolObject = GetComponent<PoolObject>();
- _label = GetComponentInChildren<TextMeshProUGUI>();
- iTween.Init(gameObject);
- }
- void Update()
- {
- transform.localPosition += new Vector3(0, upSpeed * Time.deltaTime, 0);
- }
- public void SetText(string text)
- {
- iTween.Stop(gameObject);
- _label.text = text;
- Vector3 startScale = _originalScale * 0.01f;
- transform.localScale = startScale; //otherwise NGUI would give errors
- this.ScaleTo(_originalScale, introTime, ease: MyTween.Ease.easeOutBack);
- this.ScaleTo(startScale, outroTime, introTime + stayTime, MyTween.Ease.easeInBack, () =>
- {
- _poolObject.Despawn();
- });
- if (spinColorSpeed != 0)
- {
- hsbColor = new HSBColor(startSpinColor);
- this.ValueTo(0, 1 * spinColorSpeed, introTime + stayTime + outroTime, (hue) =>
- {
- hsbColor.h = hue % 1f;
- _label.color = hsbColor.ToColor();
- });
- }
- }
- }
|