Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help needed with Animator: Opening and closing a drawer

Discussion in 'Editor & General Support' started by Alan47, Dec 28, 2019.

  1. Alan47


    Mar 5, 2011
    Hi folks,

    I've a basic cupboard mesh in my scene:

    (click the thumbnail to enlarge it)

    As you can see, the drawers are modeled separately from the frame. What I would like to do is actually quite simple:

    - if the player clicks on them, I want to animate them opening up...
    - ... and when they are clicked again I want them to close again.

    I've all the scripting done and everything works smoothly (input, raycasting etc.), except for: the animator part.

    The way the animation system in Unity is set up seems to be geared towards situations where:
    - there is a looping animation in each state
    - transitions from state A to state B transition the animations from animation A to animation B.

    In my case, there is no looping going on. I want the open/close animation to play on the state transition.

    Can I still use the built-in animator for this? Does it even make sense to use the animator? Or would it be wiser to simply use a Tween library and hard-code this one out?

    What I tried is:
    - have one 1-frame "animation clip" that shows the drawer in closed position
    - have one 1-frame "animation clip" that shows the drawer in opened position
    - transition between the states transitions the animation, and thus the position
    ... but that didn't really work out. Also, I don't want the engine to be busy playing animations all the time that effectively do nothing.
  2. Alan47


    Mar 5, 2011
    I solved it using iTween. I don't know if that's the most "unity way" of doing it, but it works nicely for my purposes :)