In C# (and most if not all other languages) there is something called an
LValue
and an
RValue
: when you do an assignment you always have an
LValue
on the left of the equals sign and an
RValue
on the right.
The
LValue
is where the value is to be stored, and the
RValue
is the value to store into it.
The
RValue
can be pretty much anything: a constant, a variable, a property, a method return value: it's an expression that can be evaluated to a single item:
666
"Hello World"
Average(new List<int>() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
2 * Math.Pi * radius * radius
But an
LValue
is much more restrictive: it has to be an object that occupies some identifiable location in memory and which can be changed. In C# that means either a variable, a field, a Property that has a accessible setter (which looks like a variable) or an Indexer (basically something that can go between square brackets).
Your code tries to have two
LValue
s:
HorizontalMove = Input.GetAxisRaw("Horizontal") = runSpeed;
Which is a short form way to say:
Input.GetAxisRaw("Horizontal") = runSpeed;
HorizontalMove = runSpeed;
HorizontalMove
is a variable, specifically a
float
so that's a valid
LValue
.
runSpeed
could be anything, but it's to the right of an equals sign, so that's OK - it's an
RValue
.
Input.GetAxisRaw("Horizontal")
is a return value from a method call, so that again could be anything: a constant, a void, whatever - which makes it an RValue as well.
So your code is trying to assign the value of
runSpeed
to an RValue, and the system complains because you can't do that!