58 lines
1.3 KiB
C#
58 lines
1.3 KiB
C#
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;
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|