Answers for "how to crouch in unity"

C#
0

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;
        }
    }
}
Posted by: Guest on April-10-2020

C# Answers by Framework

Browse Popular Code Answers by Language