- Home /
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.
Comment
Best Answer
Answer by robertbu · Nov 27, 2013 at 07:15 PM
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;
}
Your answer
Follow this Question
Related Questions
how to check if the object looks right or left? 1 Answer
Camera rotation around player while following. 6 Answers
x, y position to 360 degree 0 Answers
Aim Down Sights Positioning Problem 1 Answer