Menu
CoddyTech

복습: 입력 시스템 전환

Coddy Unity 여정의 실제 게임 만들기 섹션에 포함된 레슨. 56개 중 47번째.

challenge icon

챌린지

중급

이 버블 완드는 이전 Input 클래스를 사용해 작성되었습니다. Both로 설정된 프로젝트에서는 작동하지만, 이 프로젝트는 새 Unity 6 프로젝트처럼 설정되어 있습니다(Active Input Handling: Input System Package). Play를 누르면 첫 번째 Input 호출에서 InvalidOperationException이 발생합니다. 기존 기능을 모두 유지하면서 Input System으로 포팅하세요.

  • 방향키 또는 WASD로 잔디밭을 가로질러 완드를 초당 speed 단위로 움직입니다. 대각선으로 움직여도 더 빨라지지 않습니다.
  • Jump를 누르면 완드 위 1.5 단위 높이에 버블이 생깁니다. Jump를 누르고 있는 동안 버블은 초당 growRate만큼 커지며, 최대 크기는 maxSize입니다. 버튼에서 손을 떼면 크기를 기록합니다. 예: Bubble: 0.8.
  • 마우스 왼쪽 버튼을 클릭하면 모든 버블이 터지고 개수가 기록됩니다. 예: Popped 3.

프로젝트의 Move 및 Jump 액션과 Mouse.current를 사용하고, 스크립트에서 Input. 호출을 모두 제거하세요. Play를 눌러 시험해 본 다음 Check를 누르세요.

직접 해보기

using UnityEngine;

public class Wand : MonoBehaviour
{
    public float speed = 4f;
    public float growRate = 1f;
    public float maxSize = 1.5f;
    public GameObject bubblePrefab;

    private Transform bubble;

    void Update()
    {
        Vector3 move = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
        transform.position += move.normalized * speed * Time.deltaTime;

        if (Input.GetButtonDown("Jump"))
        {
            bubble = Instantiate(bubblePrefab, transform.position + Vector3.up * 1.5f, Quaternion.identity).transform;
        }
        if (Input.GetButton("Jump") && bubble != null)
        {
            float size = Mathf.Min(bubble.localScale.x + growRate * Time.deltaTime, maxSize);
            bubble.localScale = Vector3.one * size;
        }
        if (Input.GetButtonUp("Jump") && bubble != null)
        {
            Debug.Log("Bubble: " + bubble.localScale.x.ToString("F1"));
            bubble = null;
        }

        if (Input.GetMouseButtonDown(0))
        {
            GameObject[] bubbles = GameObject.FindGameObjectsWithTag("Bubble");
            foreach (GameObject b in bubbles) Destroy(b);
            Debug.Log("Popped " + bubbles.Length);
        }
    }
}

실제 게임 만들기의 모든 레슨