Advertisement
gameDevTeacher

Custom Animation

Jul 4th, 2023
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. public Image m_Image;
  2. public Sprite[] m_SpriteArray;
  3. public float m_Speed = .02f;
  4. private int m_IndexSprite;
  5. Coroutine m_CorotineAnim;
  6. bool IsDone;
  7. public void Func_PlayUIAnim()
  8. {
  9. IsDone = false;
  10. m_CorotineAnim = StartCoroutine(Func_PlayAnimUI());
  11. }
  12. public void Func_StopUIAnim()
  13. {
  14. IsDone = true;
  15. StopCoroutine(m_CorotineAnim);
  16. }
  17. IEnumerator Func_PlayAnimUI()
  18. {
  19. yield return new WaitForSeconds(m_Speed);
  20. if (m_IndexSprite >= m_SpriteArray.Length)
  21. {
  22. m_IndexSprite = 0;
  23. }
  24. m_Image.sprite = m_SpriteArray[m_IndexSprite];
  25. m_IndexSprite += 1;
  26. if (IsDone == false)
  27. m_CorotineAnim = StartCoroutine(Func_PlayAnimUI());
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement