Unity3D--刚体移动

Unity3D--刚体移动_第1张图片

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

public class L6_7Demo : MonoBehaviour
{
    private Rigidbody rb;

    void Start()
    {
        rb = GetComponent();
    }

   
    void Update()
    {
        

        Move();
    }

    private void Move()
    {
        //获取输入按键:
        float h = Input.GetAxis("shuiping");
        float v = Input.GetAxis("chuizhi");

        Vector3 dir = new Vector3(h, 0, v) * Time.deltaTime*10f;// y轴不变,x,z轴;根据水平(a,d 按键的输入)和(w,s 按键的输入)改变
        rb.MovePosition(transform.position+dir);

    }
}


 

你可能感兴趣的:(Unity3D,unity,游戏引擎,c#)