정해진 시간(타임바 TimeBar)이 점점 줄어들다가 시간이 종료되면 "GAME OVER" 텍스트가 나타나도록 합니다. 타임어택등의 게임에 활용하면 될 듯하네요. | Image Type(Filled), Fill Method(Horizontal)
[GameOver.cs]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameOver : MonoBehaviour
{
[SerializeField] GameObject gameOverText;
[SerializeField] float maxTime = 5f;
float timeLeft;
Image timerBar;
// Start is called before the first frame update
void Start()
{
gameOverText.SetActive(false);
timerBar = GetComponent<Image>();
timeLeft = maxTime;
}
// Update is called once per frame
void Update()
{
if(timeLeft > 0)
{
timeLeft -= Time.deltaTime;
timerBar.fillAmount = timeLeft / maxTime;
}
else
{
gameOverText.SetActive(true);
Time.timeScale = 0;
}
}
}
댓글