- Home /
Play animation when mouse drag
Hi!
Is the first time that I'm using Unity, and I'm having some issues. I have a 3D object animated in Cinema 4D that I imported to Unity. I need to play the animation of this object when I click and drag my mouse up, and rewind it when I click and drag the mouse down. What 3# script can I use to do it?
Thank you
Answer by HyperQuantum · Dec 02, 2015 at 10:04 AM
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public Animator anim;
void Update ()
{
if (input.GetKeyDown("Mouse0") && input.GetAxis("MouseY") > 0)
{
anim. SetTrigger("forwardAnimation");
}
if (input.GetKeyDown("Mouse0") && input.GetAxis("MouseY") < 0)
{
anim. SetTrigger("backwardsAnimation");
}
}
}
Note that you'll need 2 animation clips, one forward, the other backwards.
Though it is possible to manually rewind the forward clip by setting the speed to -1. Use this if you desperately want to rewind the clip.
http://docs.unity3d.com/ScriptReference/AnimationState-speed.html
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Click drag change animation speed based on dragging speed 1 Answer
Mouse move to control the animation 1 Answer