Search Unity

Unity UI Move panel by its own width

Discussion in 'UGUI & TextMesh Pro' started by tjmaul, Feb 21, 2019.

  1. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
    Hi Everyone,

    I’m trying to move a Panel in and out of the screen using an animation controller. The size of the panel is a percentage of the screen size, so I don’t know it’s width at runtime.

    I animated the RectTransforms “Left” values (Anchored Position.x in the animation window), but that obviously only works for a specific screen size.

    Any idea how I can do this independently of the screen size? Like in CSS where I could animate the transform to “translateX(-100%)”, 100% relating to the elements width.

    Any help is much appreciated!
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    It depends a bit on the hierarchy structure and the sizes of the parents. But if the parent is covering the whole screen, you can simply animate the anchorMin and anchorMax values.