Ask Sawal

Discussion Forum
Notification Icon1
Write Answer Icon
Add Question Icon

How to move ui elements unity?

2 Answer(s) Available
Answer # 1 #

Okay, I won't go into details with my game, but I've made a super-simple example which represents my issue.

I have a 2D scene these components:

When the scene loads, and I tap the button this script executes:

I have also tried this code:

The problem is, that when I click the button, the x-pos of the object sets to -1536 which is not as expected. Picture shows the scene after the button has been clicked. Notice the Rect Transform values:

So I did a little Googling and found out about ScreenToWorldPoint, WorldToScreenPoint etc but no of these conversions solves my problem.

I'm pretty sure I'm missing someting here, which probably is right in front of my, but I simply can't figure out what.

I hope someone can point me in the right direction.

[4]
Edit
Query
Report
Jenö Urban
Musician
Answer # 2 #
  • public void MoveSayDialogToTop()
  • {
  • var sayDialog = GameObject. Find("SayDialog"). transform. Find("Panel"). GetComponent();
  • var pos = sayDialog. localPosition;
  • sayDialog. localPosition = new Vector3(pos. x, 840, pos. z);
  • }
[3]
Edit
Query
Report
Haradhan Motivala
DOUGH MIXER OPERATOR