Search Unity

Scale Animation

Discussion in 'UI Toolkit' started by MousePods, Feb 10, 2021.

  1. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    Hi,

    I was wondering if there is a way to scale a certain axis. I just learned you cannot rotate on the x and y axis so I tried faking it with scale. However, it seems you can only scale with a float. Is there going to be a way to scale the x or y?

    Thanks!
     
  2. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,000
    You can apply a Vector3 scale using the transform property:
    Code (CSharp):
    1. element.transform.scale = new Vector3(0.5f, 0.5f, 1.0f);
    It's a good idea to leave the Z scaling at 1 to avoid issues.
     
  3. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    That is what I do initially, but I need to animate it back to that scale. However, I can only animate it as a single float, not the x or y.

    Screen Shot 2021-02-10 at 5.46.08 PM.png

    1. I want to set it to Vector3(1, 0, 0) which I can do.
    2. Animate it too Vector3.One which I assume works with just animating the scale to 1.
    3. Animate it back to Vector3(1, 0, 0) which I cannot do as it takes a single value
    Thanks!
     
  4. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,000
    Ah, you are correct. The Vector3 version of the Scale animation isn't yet exposed. We will fix that. Thanks for reporting.

    As a workaround, you can trigger the animation manually using animation.Start() directly:
    Code (CSharp):
    1.         var scaleTo = new Vector3(3,2,1);
    2.         var durationMs = 2000;
    3.         element.experimental.animation.Start((e) => e.transform.scale, scaleTo, durationMs, (e, v) => { e.transform.scale = v; });
    4.  
     
    MousePods likes this.
  5. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    Hey!

    Just downloaded the Beta 1 and this still hasn't been exposed. Just curious about a timeline?

    Thanks!
     
  6. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,000
    It is still in our backlog, I'll follow up on this and will let you know.
     
  7. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,000
  8. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    Ah, I did see that, but I wanted to animate this bit through code. I didn’t want to create a class in uss and add/remove it.

    Is there a way to animate via transitions through code? I couldn’t find any examples.

    EDIT: I also asked this question in the thread you posted so it has more visibility for others.

    Thanks!