- Home /
Duplicate Question:
http://answers.unity3d.com/questions/441125/c-teleport-script-error.html
C# Instant Teleport Script
Hi everyone, how do I make it so the script instantly teleports + 0.7 in the z axis? I tried transform.position.z += 0.7 but I get a cannot modify value error.
transform.position = transform.position + new Vector3(0, 0, 0.7f);
You get that error because C# doesn't let you access the vector components individually, you have to replace the whole vector.
Surely you're just $$anonymous$$sing us now?
http://answers.unity3d.com/questions/441125/c-teleport-script-error.html
@kmeboe: Well done ;) I can't even remember the question although i posted a quite detailed explanation yesterday :D
I will close this one
Answer by Howey-Do-It · Apr 20, 2013 at 10:26 PM
Transform.position.x/y/z is a read-only property. You can't modify it directly.
This should work if I understand the question correctly. By setting the X and Y values to the current position it is simply not modifying them, in case the object is not stationary on the other axes. Which I am guessing is the case.
transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + 0.7f);
Follow this Question
Related Questions
C# Teleport Script Error 1 Answer
C# Instant OnTriggerEnter Detection 0 Answers
C# GUI.Tooltip If Statement 2 Answers
C# SetActive GameObject Array 2 Answers
unity c# RPC 0 Answers