I’ve been trying to work on a Crouching Mechanic for an FPS style game. I cannot seem change the height of my capsule collider to reflect this. Here is the control portion of my code. This is all in C#
using UnityEngine
using System.Collections;
[RequireComponent (typeof(CharacterController))]
public class FPSCtrlr : MonoBehaviour {
public float CCStandHeight = 2.0f;
public float CCCrouchHeight = 1.0f;
bool crouch = false;
CharacterController characterController;
CapsuleCollider playerCollider;
// Use this for initialization
void Start ()
{
Screen.lockCursor = true;
characterController = GetComponent<CharacterController>();
playerCollider = GetComponent <CapsuleCollider>();
}
// Update is called once per frame
void Update ()
{
//Stand to Crouch
if (Input.GetButtonDown ("Crouch") && crouch == false)
{
playerCollider.height = CCCrouchHeight;
crouch = true;
}
//Crouch to Stand
if (Input.GetButtonDown ("Crouch") && crouch == true)
{
playerCollider.height = CCStandHeight;
crouch = false;
}
}
All other portions of the code work fine so I only included the part giving me problems.