using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ZZZPractice : MonoBehaviour
{
public Text timeText; // Text 변수에는 문자열만 들어감
float time; // 실수이기 때문에 문자열에 못 들어감
void Update()
{
time += Time.deltaTime;
timeText.text = time.ToString(); // 실수를 문자열로 변경해서 넣음
}
}
ToString은 보통 UI의 텍스트에 들어갈 시간이나 숫자를 넣을 때 사용한다.
time.ToString
=
time이라는 실수 값을 문자열로 변경해라.
참고사항
ToString("F2");
= 소수점 두 번째 자리까지 표시해줘.
ToString("N2");
= 소수점 두번째 자리까지 표시해주고, 천 단위 콤마 찍어줘.
'유니티' 카테고리의 다른 글
[유니티]데이터 저장 및 불러오기 PlayerPrefs (0) | 2024.12.23 |
---|---|
[유니티] 장면 Scene 불러오기 SceneManager.LoadScene (0) | 2024.12.22 |
[유니티] 지연 호출 Invoke, InvokeRepeating 사용 방법 (0) | 2024.12.21 |
[유니티 Unity] 마우스 위치에 오브젝트 위치 시키기 (ScreenToWorldPoint / Input.mousePosition) (1) | 2024.12.21 |
[유니티] 플레이어 속력 이동 (velocity / Input.GetAxisRaw) (0) | 2024.12.21 |