텍스트 크기 확대/축소 효과를 제어하는 스크립트
using System.Collections;
using UnityEngine;
using TMPro;
public class ScaleEffect : MonoBehaviour
{
[SerializeField]
[Range(0.01f, 10f)]
private float effectTime; // 크기 확대/축소 되는 시간
private TextMeshProUGUI effectText; // 크기 확대/축소 효과에 사용되는 텍스트
private void Awake()
{
effectText = GetComponent<TextMeshProUGUI>();
}
public void Play(float start, float end)
{
StartCoroutine(Process(start, end));
}
private IEnumerator Process(float start, float end)
{
float current = 0;
float percent = 0;
while ( percent < 1 )
{
current += Time.deltaTime;
percent += current / effectTime;
effectText.fontSize = Mathf.Lerp(start, end, percent);
yield return null;
}
}
}
GameOver 오브젝트에 ScaleEffect.cs 넣기(Result-GameOver)
Effect Time: 0.5

게임 오버 되었을 때 “Game Over” 텍스트의 크기를 500에서 200으로 축소하는 애니메이션 재생
public class UIController : MonoBehaviour
{
// ...
[Header("Reselt UI Animation")]
[SerializeField]
private ScaleEffect effectGameOver;
public void Awake() {}
public void GameStart()
{
mainPanel.SetActive(false);
gamePanel.SetActive(true);
}
public void GameOver()
{
int currentScore = (int)gameController.CurrentScore;
textResultScore.text = currentScore.ToString();
CalculateGradeAndTalk(currentScore);
CalculateHighScore(currentScore);
gamePanel.SetActive(false);
resultPanel.SetActive(true);
// "Game Over" 텍스트 크기 축소 애니메이션
effectGameOver.Play(500, 200);
}
public void GoToMainMenu() {}
public void GoToNotion() {}
void Update() {}
private void CalculateGradeAndTalk(int score) {}
private void CalculateHighScore(int score) {}
}
GameOver 오브젝트 추가
.png)
숫자 카운팅 효과를 제어하는 스크립트
Play(int start, int end) 메소드
Text UI에 출력하는 숫자를 start에서 end까지 effectTime 시간 동안 변화 시키는 애니메이션을 재생할 때 호출
Lerp()로 값을 변화 시킬 때는 start와 end 사이의 값이 t에 의해 결정되기 때문에 소수점이 포함된 실수가 나올 수 도 있다. 그래서 ToString() 메소드를 이용해 문자열로 변환할 때 “F0”으로 소수점이 없는 실수로 변환된다