using System.Collections;
using UnityEngine;

public class GrandmaReactionVisual : MonoBehaviour
{
    [SerializeField] private SpriteRenderer reactionRenderer;
    [SerializeField] private Sprite exclamationSprite;
    [SerializeField] private float showDuration = 2f;

    private Coroutine reactionCoroutine;

    public void ShowExclamation()
    {
        if (reactionRenderer == null || exclamationSprite == null)
            return;

        if (reactionCoroutine != null)
            StopCoroutine(reactionCoroutine);

        AudioManager.Instance.PlayExclamation();
        reactionCoroutine = StartCoroutine(ShowRoutine());
    }

    private IEnumerator ShowRoutine()
    {
        reactionRenderer.sprite = exclamationSprite;
        reactionRenderer.enabled = true;

        yield return new WaitForSeconds(showDuration);

        reactionRenderer.enabled = false;
        reactionRenderer.sprite = null;
    }
}