Unity人物控制

①运用axis进行人物移动控制

using UnityEngine;

public class MoveCtr : MonoBehaviour {
    private float _v;
    private float _h;
    private Rigidbody _rig;
    public int moveSpeed = 8;
	void Start () {
        _v = 0;
        _h = 0;
        _rig = GetComponent<Rigidbody>();
        _rig.useGravity = false;
	}
	
	void Update () {
		
	}
    private void FixedUpdate()
    {
        _v = Input.GetAxis("Vertical");
        _h = Input.GetAxis("Horizontal");
        Vector3 v3 = new Vector3(_h, 0, _v).normalized;
        _rig.velocity = v3 * moveSpeed;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_43492764/article/details/85705161
今日推荐