Unity3D学习记录——刚体移动

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

public class RigiMove : MonoBehaviour {

    private Rigidbody m_rigidbody;

	// Use this for initialization
	void Start () {
        m_rigidbody = gameObject.GetComponent();
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetKey(KeyCode.A)){
            m_rigidbody.MovePosition(m_rigidbody.position + Vector3.left * 5 * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.D)) {
            m_rigidbody.MovePosition(m_rigidbody.position + Vector3.right * 5 * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.W)) {
            m_rigidbody.MovePosition(m_rigidbody.position + Vector3.forward * 5 * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.S)) {
            m_rigidbody.MovePosition(m_rigidbody.position + Vector3.back * 5 * Time.deltaTime);
        }
	}
}

你可能感兴趣的:(Unity3D)