UI GameObject (Button prefab) randomly changing Z axis RectTransform when instantiated
I was trying to instantiate a prefab button inside a child of canvas. It's x and y axis are staying constant but Z axis is acting weird. It becomes -800 for some reason and I can't figure out why. Here is the code:
And when I press play, here is the result:
as you can see, even though I set the rectTransform to something else, it still becomes -800 (I want it to be 0 or anything I want.). Any help would be appreciated. Thank you so much and take care.
EDIT: the second pic got corrupted but you can look at it at the bottom of the post. Thanks
Answer by GameDev7 · Jan 01, 2021 at 07:14 PM
@VirtualDreamer check localPosition of the gameobject, in your case try to set gameobject.localPosition.z = 0; Hope it helps you solve your issue!
Your answer
Follow this Question
Related Questions
Moving UI buttons with code 0 Answers
Is it possible to get the screen rect for a button regardless of its parent? 1 Answer
A strategy for puzzle games: Transform or RectTransform or both? 0 Answers
UI Canvas Anchor points are stuck in the bottom left corner and disabled when in overlay mode. 1 Answer
Button Displacement 0 Answers