Menu
CoddyTech

떨어지는 별

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

challenge icon

챌린지

중급

별을 떨어뜨리세요.

  1. Catcher에 [SerializeField] private Transform star;와 [SerializeField] private float fallSpeed = 3f;를 추가하세요. 씬에서 Star를 star에 넣습니다.
  2. Update() 끝에서 Vector3.down * fallSpeed * Time.deltaTime를 포수의 위치가 아니라 star.position에 더하세요.

‘플레이’를 누르세요. 별이 포수를 지나 떨어져 계속 내려갑니다. 그런 다음 ‘확인’을 누르세요.

직접 해보기

using UnityEngine;

public class Catcher : MonoBehaviour
{
    [SerializeField] private float speed = 6f;

    void Update()
    {
        float x = transform.position.x;
        if (Input.GetKey(KeyCode.RightArrow))
        {
            x += speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            x -= speed * Time.deltaTime;
        }
        x = Mathf.Clamp(x, -4f, 4f);
        transform.position = new Vector3(x, transform.position.y, transform.position.z);
    }
}

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

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