Unity键盘控制物体移动

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

public class Move : MonoBehaviour {
    public float speed = 2f;
    private Rigidbody rigidbody;
	// Use this for initialization
	void Start () {
        rigidbody = this.GetComponent();
	}
	
	// Update is called once per frame
	void Update () {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        rigidbody.MovePosition(transform.position + new Vector3(h, 0, v) * speed * Time.deltaTime); 
	}
}

你可能感兴趣的:(unity)