Error with position

I get error:

ERROR: The left-hand side of an assignment must be a variable, a property or an indexer

What is the problem?

Jon Skeet
people
quotationmark

The type of Transform.position is Vector3, which is a struct. That means when you access it, you get a copy of the value. Then ScreenToWorldPoint takes that value and returns another Vector3. Mutating that value wouldn't do anything useful - it wouldn't change anything in the transform, which is presumably what you're trying to achieve. It sounds like you probably want something like:

var transform = GameObject.FindWithTag("Object").transform;
var position = Camera.main.ScreenToWorldPoint(transform.position);
position.x -= 10;
transform.position = Camera.main.WorldToScreenPoint(position);

Note the conversion back from world to screen co-ordinates, to keep everything in the original context.

Having written all of this, it should be noted that I've never done any Unity3d coding - this is just on the basis of regular C#.

people

See more on this question at Stackoverflow