0
\$\begingroup\$

Here is my script for opening animation. It basically sets the localPosition of an object out of the screen and then brings back in smoothly. The problem is I got different localPosition results in the game. I've done this exact way many times in my other games but I didn't have that problem in those.

public RectTransform profileParent;

public void Start()
 {
     //start position
     print("before: " + profileParent.localPosition);
     
     //set localPosition out of the screen bounds
     profileParent.localPosition = new Vector3(-150, -61f, 0);

     print("after: " + profileParent.localPosition);

     StartCoroutine(OpeningAnim());
 }

 public IEnumerator OpeningAnim()
 {
     yield return new WaitForSeconds(.3f);

     //bring back object to starting position
     profileParent.DOLocalMove(new Vector3(150, -61), .3f).SetEase(Ease.InOutQuad);
     
     print("after 2: " + profileParent.localPosition);
 }

This is Profile Parent Object before running the game, look at Pos values and location at scene

This is Profile Parent before running the game, look at Pos values and location at scene

And this is the parent objectAnd this is the parent object

When I run the game, this happens:game running

And this is the console print for localPosition console

Both transform.localPosition and transform.DOLocalMove gives different results. Like I said I've done this many times before but never faced this problem. Parent is same with my other games. Can you tell me why is this happening?

\$\endgroup\$
1
  • \$\begingroup\$ For UI objects, you more often want to work with the AnchoredPosition rather than local position. \$\endgroup\$ Commented Jan 31 at 18:03

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.