- Home /
how to fix the z position of an object
I am making a 3d side-scroller in unity and i was wondering how to fix an objects z position.
Answer by Kryptos · Jul 23, 2012 at 10:45 AM
Set the z-component to zero (or any other value that fit your need) in Update
.
Vector3 v3Position = anObject.transform.position; v3Position.z = 0; anObject.transform.position = v3Position;
Answer by schetty · Jul 23, 2012 at 07:14 PM
gameObject.transform.position.z = 2.0;
This will not work with C# because position is a delegated property that returns a copy of the position not a reference to it.
You can do it in UnityScript, but under the ground it is doing the same as my answer. So it is always better to do it explicitly.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074535im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Sidescroller Turning 1 Answer
Help implementing aiming in sidescroller via mouse. 0 Answers
Input.GetAxis to act like button 1 Answer
Unity 2D - Make Player Auto-Move? 1 Answer
How do I make a sidescrolling character work in both directions? 1 Answer