Menu
CoddyTech

하늘에서 떨어지는 블록

Coddy Unity 여정의 Unity 스크립팅 기초 섹션에 포함된 레슨. 85개 중 76번째.

challenge icon

챌린지

중급

하늘에 매초 블록을 생성하세요. 조작은 그대로 유지하세요.

  1. [SerializeField] private GameObject blockPrefab;, [SerializeField] private float spawnEvery = 1f; 및 private List<GameObject> blocks = new List<GameObject>();를 추가하세요.
  2. float timer에 Time.deltaTime을 더하고, spawnEvery에 도달하면 spawnEvery를 빼세요.
  3. 그런 다음 new Vector3(Random.Range(-laneEdge, laneEdge), 10f, 0f) 위치에 블록을 생성하고 blocks에 추가하세요.

‘플레이’를 누르세요. 블록이 레인 위 높은 곳에 나타납니다. 그런 다음 ‘확인’을 누르세요.

직접 해보기

using UnityEngine;

public class Runner : MonoBehaviour
{
    [SerializeField] private float speed = 6f;
    [SerializeField] private float laneEdge = 4f;

    void Update()
    {
        Vector3 p = transform.position;
        p.x += Input.GetAxisRaw("Horizontal") * speed * Time.deltaTime;
        p.x = Mathf.Clamp(p.x, -laneEdge, laneEdge);
        transform.position = p;
    }
}

Unity 스크립팅 기초의 모든 레슨

직접 연습해 보세요: Unity 플레이그라운드