(一)角色控制器
首先要使用CharacterController组件,在物理里面,属性面板里面可以调它们的数据大小,然后就是写脚本。
创建move脚本,首先在Start()里面获得这些组件
void Start()
{
car = GetComponent<CharacterController>();//获得角色控制器组件
player = this.transform;
}
在Update()里面写具体的实现
void Update()
{
Vector3 move = Vector3.zero;
move.x = Input.GetAxis("Horizontal") * Time.deltaTime;//获取横轴上数据段的值在x轴上移动
move.z = Input.GetAxis("Vertical") * Time.deltaTime;//获取竖轴上数据段的值在x轴上移动
move.y -= 3f * Time.deltaTime;
car.Move(player.TransformDirection(move));
}
完整代码
using UnityEngine;
public class move