This repository has been archived on 2026-04-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
monsterstalker/Assets/Scripts/Flash.cs
T
2018-04-11 16:54:57 +10:00

42 lines
786 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Flash : MonoBehaviour {
SpriteRenderer spriteRenderer;
float alpha = 1.0f;
const float gradient = 0.1f;
const float period = 0.1f;
float lastClick; //prevent double exposure
void Awake() {
spriteRenderer = GetComponent<SpriteRenderer> ();
spriteRenderer.color = new Color (1f, 1f, 1f, 0f);
}
public void StartFlash() {
StartCoroutine (FlashCoroutine ());
}
IEnumerator FlashCoroutine() {
lastClick = Time.time;
float thisClick = lastClick;
alpha = 1.0f;
while (alpha > 0) {
yield return new WaitForSeconds (period);
if (thisClick != lastClick) {
break;
}
alpha -= gradient;
spriteRenderer.color = new Color (1f, 1f, 1f, alpha);
}
}
}