Menu
CoddyTech

시간 안에 끝내기

Coddy Unity 여정의 물리와 게임플레이 섹션에 포함된 레슨. 71개 중 32번째.

challenge icon

챌린지

중급

Coin Rush에 시계를 추가하세요.

  1. Ball.cs에 public float timeLimit = 60f;와 public float timeLeft;를 추가하고, Start()에서 timeLeft = timeLimit;을 설정하세요.
  2. 새 Update()에서 timeLeft > 0f인 동안 Time.deltaTime을 빼세요. 0이 되면 0f로 설정하고 "Time's up! Score: " + score를 로그에 출력하세요.
  3. 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 플레이그라운드