- Home /
UI element stuck in position on screen?
So I'm making a sort of progress bar that appears and goes to the location on the screen a player presses. I had success doing this already and I got a health bar to appear where my mouse was, but for some reason, I've copied over my code from that to this nearly identical slider and yet instead of going to the correct position, it goes to the corner of the screen. Here is the code from the first bar:
hpBar.GetComponent<RectTransform>().position = Input.mousePosition + new Vector3(0, 30, 0);
Again, this line works perfectly. It references a gameobject called hpBar on another script with a slider component attached to it, gets its rectTransform, and moves it.
I did make a few changes to the code in the second bar:
playerScript.researchBar.GetComponent<RectTransform>().position = new Vector3(transform.position.x, transform.position.y + 1, 0);
I've already tried a good bit of troubleshooting, like setting the position to a new Vector3(0,0,0), and confirming that the components on both bars are the exact same.
Unless I've made a mistake in the second line, I realize it must be some outside factor... but I have scoured my code and nowhere else do I set the position of this gameobject. This is literally the only line where that happens.
Any help would be appreciated.
Your answer
Follow this Question
Related Questions
How to Force a Layout Group to Rebuild 0 Answers
this code doesnt work when the buttons anchor are not same(custom anchor) 0 Answers
Moving a UI image by script 1 Answer
Position auto-scaled UI element with Camera.WorldToScreenPoint 2 Answers
Strange UI scrollbar handle recttransform behaviour,Cant resize clickable area on UI handle 1 Answer