적고 싶은 글자를 WarningTextValue에 적어둔 다음에,
Substring을 이용하여 한글자씩 나타나도록 한다.
TextUpdateInterval로 시간 간격을 정한다음에, Time.time으로 시간을 업데이트 하는 방식 사용.
const float TextUpdateInterval = 0.1f; //글자가 나타나는 시간 간격
const string WarningTextValue = "Warning...."; //적으려는 텍스트
[SerializeField]
Text WarningText; //텍스트 연결해주고
int TextIndex = 0;
float LastUpdateTime;
void Update()
{
float currentTime = Time.time;
if(currentTime - LastUpdateTime > TextUpdateInterval) //시간 간격 마다 한 글자씩 나타남
{
WarningText.text = WarningTextValue.Substring(0, TextIndex + 1); //Substring을 이용
TextIndex++;
if(TextIndex >= WarningTextValue.Length) //글자 다 적으면 처음으로
{
TextIndex = 0;
}
LastUpdateTime = currentTime;
}
}
'유니티' 카테고리의 다른 글
[유니티] DateTime.Utc로 시간 기록/시분초 구현하기 (0) | 2023.03.16 |
---|---|
[유니티] Prefab을 Script에서 불러오기(Resource 폴더 사용) (0) | 2023.03.16 |
[유니티] DOTween이용해서 Panel 깜빡이기 (0) | 2023.03.09 |
[유니티] EASY SAVE와 GPGS를 이용하여 클라우드 저장하기 (0) | 2023.03.05 |
[유니티] 블루투스 헤드폰, 이어폰, 스피커 사용 시 소리 멈추는 현상 (0) | 2023.03.01 |