IEnumerator PlayAnimation(SO_AnimationValues sOAV) { float timer = 0f; int spriteCount = 0; int loopCount = 0; bool playing = true; spriteR.color = sOAV.color; yield return(new WaitForSeconds(sOAV.Cooldown)); while (playing) { timer += Time.deltaTime; if (timer > sOAV.spriteTimings[spriteCount]) { spriteR.sprite = sOAV.sprites[spriteCount]; if (spriteCount < sOAV.spriteTimings.Length - 1) { spriteCount++; } } if (timer > sOAV.totalDuration) { if (sOAV.loop) { if (sOAV.loopAmnt > 0) { loopCount++; if (loopCount >= sOAV.loopAmnt) { spriteR.sprite = null; playing = false; } } timer = 0f; spriteCount = 0; if (sOAV.maxCooldown > 0) { if (sOAV.spriteOnCooldown) { spriteR.sprite = sOAV.cooldownSprite; } else { spriteR.sprite = null; } yield return(new WaitForSeconds(sOAV.Cooldown)); } } else { spriteR.sprite = null; playing = false; } } yield return(null); } }
public void StartAnimation(SO_AnimationValues sOAnimValues) { StartCoroutine(PlayAnimation(sOAnimValues)); }