- Home /
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?
Comment
Answer by syclamoth · Feb 05, 2012 at 02:15 PM
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).
Your answer
Follow this Question
Related Questions
Trouble making money system 1 Answer
Convert type `float' to `bool', Load 1 Answer
Cannot implicitly convert type 'float' to 'bool' 3 Answers
Fixed but there is still one error (see code for error) help please :) 1 Answer
convert object to float 2 Answers