55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Lemon.GenericLib.VFX
|
|
{
|
|
//need to be further developed
|
|
public class SpriteFlicker : MonoBehaviour
|
|
{
|
|
private SpriteRenderer sr;
|
|
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
sr = GetComponent<SpriteRenderer>();
|
|
}
|
|
|
|
public void FlickerSprite(float duration, int intervals)
|
|
{
|
|
StopCoroutine("FlickerSpriteRoutine");
|
|
StartCoroutine(FlickerSpriteRoutine(duration, intervals));
|
|
}
|
|
|
|
IEnumerator FlickerSpriteRoutine(float duration, int intervals)
|
|
{
|
|
for (int i = 0; i < intervals; i++)
|
|
{
|
|
if (i > 0)
|
|
{
|
|
//if (i == 1) Camera_Controller.instanceCC.ApplyScreenShake(0.05f);
|
|
|
|
if (sr.maskInteraction == SpriteMaskInteraction.None)
|
|
{
|
|
|
|
sr.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
|
}
|
|
else
|
|
{
|
|
sr.maskInteraction = SpriteMaskInteraction.None;
|
|
}
|
|
}
|
|
|
|
yield return new WaitForSeconds(duration / intervals);
|
|
}
|
|
sr.maskInteraction = SpriteMaskInteraction.None;
|
|
}
|
|
|
|
public void StopFlicker()
|
|
{
|
|
StopCoroutine("FlickerSpriteRoutine");
|
|
sr.maskInteraction = SpriteMaskInteraction.None;
|
|
}
|
|
}
|
|
} |