csharp/1ZouLTReX1/FP-MOG/top%20down%20shooter/Assets/Scripts/AnimatedTexture.cs

AnimatedTexture.cs
using UnityEngine;
using System.Collections;

public clast AnimatedTexture : MonoBehaviour
{
    public float fps = 20.0f;

    private Coroutine co;
    [SerializeField] private GameObject muzzelFlashGO;

    public void Flash()
    {
        if (this.isActiveAndEnabled)
        {
            if (co != null)
                StopCoroutine(co);
            co = StartCoroutine(StartFlash());
        }
    }

    IEnumerator StartFlash()
    {
        muzzelFlashGO.SetActive(true);
        yield return new WaitForSeconds(1 / fps);
        muzzelFlashGO.SetActive(false);
    }
}