This code:
transform.position.y += floatHeight; //floatHeight is a float
…gives this error:
The same code in Javascript doesn’t give me any trouble.
I’m new to C#. What am I missing?
This code:
transform.position.y += floatHeight; //floatHeight is a float
…gives this error:
The same code in Javascript doesn’t give me any trouble.
I’m new to C#. What am I missing?
Aras gave a great explanation in another thread:
So here you’ll need to do:
Vector3 posTemp = transform.position.
posTemp.y += floatHeight;
transform.position = posTemp;
Then why does this work:
transform.position += new Vector3(0.0f, floatHeight, 0.0f);
Because the += operator reads the current value, does the addition, then assigns it back to transform.position. That’s allowed. The thing that isn’t allowed is editing part of a struct in a property.
Ok, thanks.