Menu
CoddyTech

Zamana Karşı Yarış

Coddy'nin Unity Journey'sinin Fizik ve Oynanış bölümünün bir parçası. Ders 32 / 71.

challenge icon

Görev

Orta

Coin Rush'a bir saat ekle.

  1. Ball.cs dosyasına public float timeLimit = 60f; ve public float timeLeft; ekle; Start() içinde timeLeft = timeLimit; olarak ayarla.
  2. Yeni bir Update() içinde, timeLeft > 0f olduğu sürece Time.deltaTime değerini bundan çıkar; 0 olduğunda 0f olarak ayarla ve "Time's up! Score: " + score mesajını günlüğe yaz.
  3. FixedUpdate() içinde yalnızca timeLeft > 0f olduğu sürece it.

“Oyna” düğmesine bas ve saati izle. Ardından “Kontrol et” düğmesine bas.

Kendin dene

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);
    }
}

Fizik ve Oynanış bölümündeki tüm dersler

Kendi başına pratik yap: Unity playground