- Home /
This question was
closed Jun 12, 2018 at 12:30 PM by
GregoryFenn for the following reason:
Question is off-topic or not relevant
Question by
GregoryFenn · Jun 12, 2018 at 12:27 PM ·
c#functionsparametersmethods
Optional parameter, editor raises error "Unexpected symbol `=' "
I have a very simple maths function with an optional parameter, used in Unity 2018.2.0b5
bool IsApproxEqual(float x, float y, scaler = 1.5f){ // line 15
// float params to handle ints and floats (but not doubles like 3.4, use 3.4f instead)
return (Mathf.Abs(x - y) < scaler*Mathf.Epsilon);
}
and this syntax fits that given in reference [1]. Further, Microsoft offer the following example [2]:
public void ExampleMethod(int required, string optionalstr = "default string", int optionalint = 10)
and yet, the compiler insists on raising the error: Assets/_MyAssets/Scripts/EnemyBehaviour.cs(15,48): error CS1525: Unexpected symbol `='
Does anyone know what I'm doing wrong?
Comment
Follow this Question
Related Questions
Animation Event don't show C# methods 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
space wrap 3D 1 Answer