728x90
728x170

물체를 이동하는 Script 입니다.
키보드 화살표나 WASD 를 통해 움직이고 space bar 로 점프합니다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMove : MonoBehaviour
{
    float speed  = 5;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        // 거리 = 속력 * 시간
        h = h * speed * Time.deltaTime;
        v = v * speed * Time.deltaTime;

        transform.Translate(h * Vector3.right);
        transform.Translate(v * Vector3.forward);

        // 점프
        bool isJump = Input.GetKeyDown(KeyCode.Space);

        if (isJump)
        {
            transform.Translate(2 * Vector3.up);
        }
    }
}

위 Script 를 원하는 object 에 add 하면 동작합니다.
 
결과

728x90
그리드형
Posted by kjun
,