Moving an object to an x postion

I’m trying to make my object move to the starting position once it has gone past a certain co-ordinate but it just keeps erroring up. Here is my code:

if(transform.position.x < -161.0f)
	{
		print ("Enemy hit the end of the map!");
		transform.position.x = -77.59406f;
	}

error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’.
And the error. What am I doing wrong?

Thanks, Nick.

1 Answer

1

You must be using C#. You have to do:

if (transform.position.x < -161.0f)
    {
       print ("Enemy hit the end of the map!");
       Vector3 v3 = transform.position;
       v3.x = -77.59406f;
       transform.position = v3;
    }