Crouching Help

Here is the script:

public void crouch ()
{
	controller.height = crouchHeight;
	controller.center = new Vector3 (0, -0.5f, 0);
	mainCamera.transform.localPosition.y -= new float(crouchHeight);
        crouching = true;
}

And Unity gives me this error:

Assets/Scripts/Crouching.cs(31,96): error CS1729: The type float' does not contain a constructor that takes 1’ arguments

Any Help?

It’s this line here-

mainCamera.transform.localPosition.y -= new float(crouchHeight);

You don’t need to use a constructor for floats, you can just use the existing variable:

mainCamera.transform.localPosition.y -= crouchHeight;

(or, more correctly)

mainCamera.transform.Translate(Vector3.up * -crouchHeight);

The error occurs because you are trying to use an invalid constructor for the float type (that takes an argument).