- Home /
Problem with a Unity Scripting example from the scripting manual!
I was just looking forward to add some dolly zoom to my camera, and I went straight forward to the Unity's scripting reference here. I'm working with C# so I just copy pasted the C# source. However, I'm getting this errors:
Assets/Scripts/CameraPerspective.cs(15,9): error CS0127: `CameraPerspective.FrustumHeightAtDistance(float)': A return keyword must not be followed by any expression when method returns void
And
Assets/Scripts/CameraPerspective.cs(15,9): error CS0029: Cannot implicitly convert type `float' to `void'
I understand what the error is telling me, but I don't understand why the reference is written in this manner, and how could I fix this up.
Good catch, looks like you found a typo in the manual:
// Calculate the FOV needed to get a given frustum height at a given distance.
void FOVForHeightAndDistance(float height, float distance) {
return 2.0f * $$anonymous$$athf.Atan(height * 0.5f / distance) * $$anonymous$$athf.Rad2Deg;
}
That definitely don't look right, I don't know where this sort of thing would get reported, though.
Yep, there shouldn't be any expression following the return keyword as this is a void method. However, there it is. I hope someone can explain it : )
the return type needs to be float. from the method name it's expected. it's just that the manual seems to be wrong here. toy could report this as a bug with the bug reporting tool from the editor (Help -> Report a Bug)
Your answer
Follow this Question
Related Questions
Player Sprite Changing Scenes And getting a new camera to follow it and default spawn position 1 Answer
Accessing a script only using its string 3 Answers
Lock player movement within screen bounds 2 Answers
Script sets same value to other script in all objects instead of just one. 1 Answer
Unity Camera and transform? 1 Answer