So if you have a function parameter, and there is a if greater then or equals to such as this
public void yes (float amount) {
if (amount => 0.5)
{
}
}
it will give back the error
error CS0136: A local variable named 'amount' cannot be declared in this scope because it would give a different meaning to 'amount', which is already used in a 'parent or current' scope to denote something else
but take away the = and its sine?
That’s not a bug, that’s a syntactical error on your part.
The =>
operator is used to define inline anonymous lambdas, which are basically anonymous functions that take one or more parameters and return a value.
So amount => 0.5
is actually
// The ? is because the compiler can't infer the type of the argument
delegate(? amount) {
return 0.5;
}
Since you’ve already defined the amount
variable before, the compiler can’t use the same name for the anonymous function parameter.
I think you meant amount >= 0.5f
(You should put the f
after every number because Unity works with float
s and not double
s).
Remember, the conditional operator ( <
or >
) always comes before the =
in a less/greater than equal to operator ( <=
and >=
)