r/UnityHelp • • 2h ago

GameObject.transform.position.x += 0.1f not doing anything

The title, even though position.x is a float, nothing appears to move, and no errors appear

Here is the code

 Vector3 pressPos = presser.transform.position;

 string DisplayNum = CounterNumber.ToString("D4");
     for (int i = 0; i < 9; i += 1)
     {
     pressPos.x += 0.1f;
     } 
1 Upvotes

2 comments sorted by

View all comments

1

u/ChaseCheetah 52m ago

Are you, later in the code, setting the presser.transform.position = pressPos?

Vector3 is a struct so it is passed by value, not reference, so you need to then update the original value with the updated one.