WinterJamSnowman/Assets/Scripts/LemonGenericLib/Visual Effects/HitFlash.cs

58 lines
1.3 KiB
C#
Raw Permalink Normal View History

2023-01-30 16:21:55 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Lemon.GenericLib.VFX {
public class HitFlash : MonoBehaviour
{
public float flashDuration = 0.1f;
public SpriteRenderer sr;
public Material flashMaterial;
private Material defaultMaterial;
public bool getSR = false;
private void Start()
{
if (getSR) sr = GetComponent<SpriteRenderer>();
defaultMaterial = sr.material;
}
public void SetFlash(bool isFlashing = true)
{
if (isFlashing) sr.material = flashMaterial;
else sr.material = defaultMaterial;
}
public void Flash()
{
StartCoroutine(FlashRoutine());
}
public void Flash(float duration)
{
StartCoroutine(FlashRoutine(duration));
}
IEnumerator FlashRoutine()
{
sr.material = flashMaterial;
yield return new WaitForSeconds(flashDuration);
sr.material = defaultMaterial;
}
IEnumerator FlashRoutine(float duration)
{
sr.material = flashMaterial;
yield return new WaitForSeconds(duration);
sr.material = defaultMaterial;
}
}
}