public bool detectCollisions ;

Description

确定其他刚体或角色控制器是否与该角色控制器碰撞(默认情况下始终启用它)。

This method does not affect collisions detected during the character controller's movement but rather decides whether an incoming collider will be blocked by the controller's collider. For example, a box collider in the Scene will block the movement of the controller, but the box may still fall through the controller if detectCollisions is false. This property is useful to disable the character controller temporarily. For example, you might want to mount a character into a car and disable collision detection until it exits the car again.

using UnityEngine;

public class Example : MonoBehaviour { CharacterController controller;

void Start() { controller = GetComponent<CharacterController>(); controller.detectCollisions = false; } }