using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

public class CanvasAnimator : MonoBehaviour
{
    public RawImage targetRawImage;


    public Texture2D[] bubbleBlowFrames;
    public Texture2D[] kickFrames;
    

    public float frameRefreshRate;

    public void blowBubble()
    {
        StartCoroutine(AnimationCoroutine(bubbleBlowFrames));
    }

    public void kick()
    {
        StartCoroutine(AnimationCoroutine(kickFrames));
    }

    public bool isAnimationRunning()
    {
        return animationRunning;
    }

    bool animationRunning;

    IEnumerator AnimationCoroutine(Texture2D[] frames)
    {
        animationRunning = true;

        int currentFrameIndex = 0;
        while (currentFrameIndex < frames.Length)
        {
            targetRawImage.texture = frames[currentFrameIndex];
            currentFrameIndex += 1;


            yield return new WaitForSeconds(frameRefreshRate);
        }

        animationRunning = false;
        yield return null;  
    }


    public bool debug_runBubbleBlowAnimation, debug_runKickAnimation;

    // Update is called once per frame
    void Update()
    {
        if (debug_runBubbleBlowAnimation)
        {
            blowBubble();


            debug_runBubbleBlowAnimation = false;
        }
    }
}
