移动代码如下所示
using UnityEngine;
using System.Collections;
public class PersonMoveControl : MonoBehaviour
{
public KeyCode mKeyLeft = KeyCode.LeftArrow;
public KeyCode mKeyRight = KeyCode.RightArrow;
public KeyCode mKeyForward = KeyCode.UpArrow;
public KeyCode mKeyBackward = KeyCode.DownArrow;
//public float mKeyStrokeMoveStep = 0.07f; //metre
private Vector3 mMoveDir ;
private Transform PlayerTransform;
//private Rigidbody rigidbody;
private Vector3 targetpos;
//移动速度
public float MoveSpeed=1.5F;
//奔跑速度
public float RunSpeed=4.5F;
&nbs

这篇博客介绍了如何在Unity中使用代码控制角色移动,包括前后左右的方向控制,并结合重力实现更加真实的移动效果。通过调整重力参数,可以消除角色移动时的漂浮感。文章提供了具体的C#代码示例,详细解释了关键代码段的作用。
最低0.47元/天 解锁文章
839

被折叠的 条评论
为什么被折叠?



