시간 안에 끝내기
Coddy Unity 여정의 물리와 게임플레이 섹션에 포함된 레슨. 71개 중 32번째.
챌린지
중급Coin Rush에 시계를 추가하세요.
Ball.cs에public float timeLimit = 60f;와public float timeLeft;를 추가하고,Start()에서timeLeft = timeLimit;을 설정하세요.- 새
Update()에서timeLeft > 0f인 동안Time.deltaTime을 빼세요. 0이 되면0f로 설정하고"Time's up! Score: " + score를 로그에 출력하세요. FixedUpdate()에서는timeLeft > 0f인 동안에만 힘을 가하세요.
‘플레이’ 버튼을 누르고 시계를 확인하세요. 그런 다음 ‘확인’ 버튼을 누르세요.
직접 해보기
using UnityEngine;
public class Ball : MonoBehaviour
{
public float force = 10f;
public int score;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
rb.AddForce(new Vector3(x, 0f, z) * force);
}
public void AddScore(int points)
{
score += points;
Debug.Log("Score: " + score);
}
}
물리와 게임플레이의 모든 레슨
직접 연습해 보세요: Unity 플레이그라운드