Version: 2023.1
public bool SimpleMove (Vector3 speed);

描述

speed 移动该角色。

忽略沿 Y 轴的速度。 速度为单位/s。重力自动施加。 如果该角色落地,则返回。 建议每帧只调用一次 MoveSimpleMove

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(CharacterController))] public class ExampleClass : MonoBehaviour { public float speed = 3.0F; public float rotateSpeed = 3.0F;

void Update() { CharacterController controller = GetComponent<CharacterController>();

// Rotate around y - axis transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);

// Move forward / backward Vector3 forward = transform.TransformDirection(Vector3.forward); float curSpeed = speed * Input.GetAxis("Vertical"); controller.SimpleMove(forward * curSpeed); } }