화면에 점수 표시
Coddy Unity 여정의 실제 게임 만들기 섹션에 포함된 레슨. 56개 중 30번째.
챌린지
중급러너가 지금까지 얼마나 왔는지 보여 주세요. 이전 레슨에서 만든 내용을 모두 유지하세요. 캔버스의 왼쪽 위에는 DistanceText가 있고, 씬에서는 이를 GameManager의 새 distanceText 필드에 연결합니다. GameManager에서 다음을 수행하세요.
using TMPro;,public TMP_Text distanceText;필드, 그리고distance라는 이름의float를 추가하세요.- 매 프레임마다 도로가 움직인 거리를 더하세요. 도로는 초당
speed미터 이동하므로, 이번 프레임에는speed * Time.deltaTime미터 이동합니다. - 내림하여 정수 미터 단위로 표시하세요. 예:
Distance: 44 m.
Play를 눌러 미터 수가 올라가는 것을 확인한 다음, Check를 누르세요.
직접 해보기
using UnityEngine;
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public float speed = 10f;
public float speedUp = 0.5f;
public float maxSpeed = 20f;
void Awake()
{
Instance = this;
}
void Update()
{
speed = Mathf.Min(speed + speedUp * Time.deltaTime, maxSpeed);
}
}