/
TON618OFF
/
Unity-Project-RTU
Обзор
Документация
Войти
/
TON618OFF
/
Unity-Project-RTU
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Library/PackageCache/com.unity.testtools.codecoverage@1.2.6/Samples~/Tutorial/Asteroids/Scripts/UI/LifeCounter.cs
63 строки
1 KB
TON618OFF
release
03 окт 2024, 22:20
03 окт 2024, 22:20
7c70e9f
Код
Авторство
О чём код?
using UnityEngine; public class LifeCounter : MonoBehaviour { public static LifeCounter instance; int previousLifeCount = 3; Animator[] lives; public Sprite lifeVisual; public Sprite emptyLifeVisual; void OnEnable() { if (instance == null) instance = this; else if (instance != this) Destroy(gameObject); } void Start() { lives = transform.GetComponentsInChildren<Animator>(); } public void SetLives(int currentLives) { if (currentLives > 3) currentLives = 3; if(currentLives <= previousLifeCount) { for (int i = 0; i < 3; i++) { if (i >= currentLives) { if (i < previousLifeCount) { lives[i].enabled = true; lives[i].SetTrigger("Remove"); } } } } else { for (int i = 0; i < 3; i++) { if (i <= currentLives) { if (i >= previousLifeCount) { lives[i].enabled = true; lives[i].SetTrigger("Recover"); } } } } previousLifeCount = currentLives; } }