Trash Flight 만들기(6) – 키보드로 움직이기

1 5
2 5
3 5
4 6
5 5
6 5
public class Player : MonoBehaviour
{

    [SerializeField]
    private float moveSpeed;

    // Update is called once per frame
    void Update()
    {
        float horizontalInput = Input.GetAxisRaw("Horizontal");
        float verticalInput = Input.GetAxisRaw("Vertical");
        Vector3 moveTo = new Vector3(horizontalInput, verticalInput, 0f);
        transform.position += moveTo * moveSpeed * Time.deltaTime;
    }
}

7 6
8 5
9 5
10 5
void Update()
    {
        // float horizontalInput = Input.GetAxisRaw("Horizontal");
        // //float verticalInput = Input.GetAxisRaw("Vertical");
        // Vector3 moveTo = new Vector3(horizontalInput, 0f, 0f);
        // transform.position += moveTo * moveSpeed * Time.deltaTime;
    
        Vector3 moveTo = new Vector3(moveSpeed * Time.deltaTime, 0, 0);
        if (Input.GetKey(KeyCode.LeftArrow)) {
            transform.position -= moveTo;
        } else if (Input.GetKey(KeyCode.RightArrow)) {
            transform.position += moveTo;
        }
    }

댓글 남기기