Question by
Okeynp · Dec 11, 2017 at 12:18 PM ·
transform.positiontransform.translate
Moving a 2d object on X axis by transform.translate
Hi, i'm making a 2d game in which the player can move along X axis by fixed distance when 2 UI buttons (left and right) are clicked. this is what i'm using:
public void GoLeft()
{
transform.Translate (-0.2f, 0f, 0f);
}
public void GoRight()
{
transform.Translate (0.2f, 0f, 0f);
}
At first look its working fine, but when i look to the tranform component in the editor the values of position are going mad. After moving the object several times i see that when i return it to x=0 the position.x on editor is 2.9802 and when i move it to x=1 in the editor position.x=0.999999. I can't neglect this glitch because i'm going to need to use the object position later. Do you have an idea how to correct this ?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612144358im_/https://answers.unity.com/themes/thub/images/avi.jpg)