1
votes

Original question on the Unityforums here

I've been trying to get an animation to not only slow down and speed up, but also play backwards depending on user input for my Hololens-application. I am using the Mecanim system, not legacy animations.

The whole thing is supposed to happen at runtime, through dynamic user input.

I know that it's possible through scripting, as I had it working before I lost local progress and some files during some Unity-Collaborate issues. As stupid as it sounds, since then I have not been able to remember what I did different from my current approach.

Right now I'm manipulating the value Animator.speed, but that only works for values >= 0.

Any help would be greatly appreciated!

Edit: In case the link is not working or visible for anybody, here is my code:

private Animator anim;
 //...
 anim = gameObject.GetComponent<Animator>();
 //...
 public void OnManipulationUpdated(ManipulationEventData eventData)
     {
         if (anim.isActiveAndEnabled)
         {

             anim.speed = eventData.CumulativeDelta.x;
             anim.Play("KA_Cover_Anim");
             return;
         }
         //...
     }

Edit2: Incorrectly marked as dupicate! The linked question does not regard a similar problem and required a different solution

Edit3: For clarification, the linked "duplicate" uses the legacy animation system which is irrelevant for my question. In Mecanim, the new animation system in Unity 5.xx, you can not access the Animations directly as shown in the selected answer. Neither is it possible to alter the animation speed as shown in in the second answer.

1
You have to show what you have tried - Programmer
You have to read what I write: "Right now I'm manipulating the value Animator.speed, but that only works for values >= 0." Dont mean to sound like a douche but I clearly did clarify what I attmepted and also didn't ask anyone to write me code. - TillEmpea
"You have to read what I write:" Attitude like this wont get you anywhere. I was only trying to help. How can we know why it's not working without your code? Good luck with that! - Programmer
I may have misinterpreted but your first comment seemed quite similar in attitude, so I responded like that. Weird that you misuse your reputation to downvote the question after you felt offended by a comment. I genuinely tried to clarify that I'm not taking a jab at you, just that I very clearly stated my attempt and that I'm not looking for someone to do it for me. - TillEmpea
Oh also, you kind of coul've followed the link I provided that shows you exactly my code ;) - TillEmpea

1 Answers

2
votes

I'm not exactly sure what you're end goal is, but you can play animations backwards and at different speeds by using a parameter.

enter image description here

On the animation state, you can make it watch a parameter and multiply it against the default speed of the animation. All you need to do in code is something like

animator.setFloat("Speed",-1.0f);

Hope that helps.