public CharacterController controller; void Jump() { if (controller.isGrounded) { controller.ChangeState(CharacterState.Jumping); controller.velocity += new Vector3(0, jumpHeight, 0); } }
public CharacterController controller; void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Water") { controller.ChangeState(CharacterState.Swimming); } }In this example, a method called OnTriggerEnter is defined that checks if the character controller has collided with an object with the tag "Water". If it has, the character controller's state is changed to "Swimming" using the ChangeState method. Both examples use the ChangeState method to modify the character controller's state in response to different conditions. The package library used is the Unity Standard Assets.