Made Game/Top Down Shooting Game

총알이펙트 및 Enemy 파괴 이펙트

JiHxxn 2024. 3. 16. 15:22

 

총구섬광 및 Enemy 파괴 이펙트
using UnityEngine;

public class Muzzleflash : MonoBehaviour
{
    [SerializeField] private GameObject flashHolder;

    [Header("[Flash Image]")]
    [SerializeField] private Sprite[] flashSprites;
    [SerializeField] private SpriteRenderer[] spriteRenderers;

    [Header("[Flash Time]")]
    [SerializeField] private float flashTime = 0.4f;

    private void Start()
    {
        Deactivate();
    }

    /// <summary>
    /// 플래쉬 활성화
    /// </summary>
    public void Activate()
    {
        flashHolder.SetActive(true);

        int flashSpriteIndex = Random.RandomRange(0, flashSprites.Length);

        for (int i = 0; i < spriteRenderers.Length; i++)
        {
            spriteRenderers[i].sprite = flashSprites[flashSpriteIndex];
        }

        Invoke("Deactivate", flashTime);
    }

    private void Deactivate()
    {
        flashHolder.SetActive(false);
    }
}