unity player crouching code example
Example: how to crouch in unity
///requires character controller to be on player
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController rb;
void Start() {
rb = GetComponent<Rigidbody>();
}
void Update() {
if(Input.GetKey(KeyCode.C)) {
controller.height = 1f;
isCrouching = true;
speed = crouchWalk;
}
else
{
controller.height = 2f;
isCrouching = false;
speed = walkSpeed;
}
}
}