neon_run/Assets/Scripts/LivesVisualizer.cs
2025-11-13 22:37:47 +05:30

38 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LivesVisualizer : MonoBehaviour
{
public Transform livesParent;
public static LivesVisualizer instance;
public void Awake(){
instance = this;
SetLives(3);
}
public void SetLives(int lives){
for(int i = 0; i < livesParent.childCount; i++){
bool prevState = livesParent.GetChild(i).gameObject.activeSelf;
bool newState = i < lives;
if(prevState != newState){
StartCoroutine(FlashLife(livesParent.GetChild(i).gameObject,newState));
}
}
}
float flashDuration = 0.3f;
IEnumerator FlashLife(GameObject life, bool state){
life.SetActive(state);
for(int i=0; i < 4; i++){
life.SetActive(!state);
yield return new WaitForSeconds(0.1f);
life.SetActive(state);
yield return new WaitForSeconds(0.1f);
}
life.SetActive(state);
}
}