Keith Power
Keith Power

Reputation: 14141

Unity adding to transform moves too far

I have a form and I want to shift the inputs/children of the form down to show an error message when needed.

I can loop over the children and I just want to shift then each down 20 pixels which are about the height of the error text but the input moves about 3000 down the x-axis. I am sure it is going to be obvious what I am doing wrong.

foreach (Transform child in Form.transform)
{
    Vector3 p = child.position;
    Debug.Log(child.name);
    p.x += 20f;
    child.position = p;
}

Upvotes: 1

Views: 48

Answers (1)

aybe
aybe

Reputation: 16662

Here's an alternative approach:

  • in your interface, create a panel or scroll view or whatever container to hold your UI
  • add a vertical layout group say if you want to lay items out in a vertical fashion
  • add your placeholder control disabled, e.g. a Text or whatever
  • whenever you want to display an error, enable this control with appropriate content

The layout system will take care of shifting all elements positions for you.

Upvotes: 2

Related Questions