Transform position script errors

The script is fine for me it does the job however in inspector I have the onclick setup and the random positions but the button on click doesn’t go to a specified one. When I press play the tile (button) starts at X 0, a defined position. But in the random position tab under my button when I click it it goes to a random position but always the same 1 or 2 as I have only 2 different values for testing. If I put x 10 it goes X 430 and X 0 X 432.4 for some reason. I don’t know why this is but the transform position script may have an error but I think it is just the canvas

Hi there, I’m having a hard time deciphering your problem as it’s written, but I’ll try my best.


It sounds like this script is running on your UI. UI Elements use RectTransforms instead of regular Transforms. The UI inspector doesn’t show position values the same way other gameobjects do. Instead, your Vector3 positions will manifest as an anchored position in a RectTransform. Try using public Vector2[] positions (instead of public Vector3 positions) and GetComponent<RectTransform>().anchoredPosition (instead of transform.position)