StarAchieved.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using DG.Tweening;
  5. public class StarAchieved : MonoBehaviour
  6. {
  7. public Image full;
  8. public SoundEvent starSound;
  9. Vector3 _originalScale;
  10. const float INIT_DELAY = 1;
  11. const float DELAY_INCREMENT_PER_STAR = 0.25f;
  12. const float TRANSITION_TIME = 0.5f;
  13. void Awake()
  14. {
  15. _originalScale = full.transform.localScale;
  16. }
  17. void OnEnable()
  18. {
  19. full.color = new Color(full.color.r, full.color.g, full.color.b, 0);
  20. }
  21. public void Animate(int index)
  22. {
  23. float delay = INIT_DELAY + index * DELAY_INCREMENT_PER_STAR;
  24. full.StopAllCoroutines();
  25. full.color = new Color(full.color.r, full.color.g, full.color.b, 0);
  26. full.DOFade(1, INIT_DELAY + index * DELAY_INCREMENT_PER_STAR);
  27. full.transform.localScale = _originalScale*2;
  28. full.ScaleTo(_originalScale, TRANSITION_TIME, delay, MyTween.Ease.easeInOutBounce);
  29. SoundManager.Play(starSound);
  30. }
  31. void OniTweenUpdateAlpha(float newAlpha)
  32. {
  33. full.color = new Color(full.color.r, full.color.g, full.color.b, newAlpha);
  34. }
  35. }