- Home /
Animation On Mouse Click
What im trying to do is have an animation to be played when the the left mouse button is clicked. I have already modelled a gun rigged it and added a recoil animation on blender which ive imported into unity, and now i need to script it which i cannot do. I have looked for tutorials for this everywhere but they dont work can anyone help me? I am trying to learn script by the way.
Answer by jahroy · Sep 17, 2011 at 07:24 PM
It was surprisingly easy to add an animation to our project.
The animation is part of the model we imported from Maya.
Our model had one animation.
To trigger it, we add a script with code like this to the model in the scene:
function Update ()
{
if ( Input.GetButtonDown("Fire1") ) {
transform.animation.Play();
}
}
Holy crap! i wasnt expecting it to be that easy thanks a lot! oh and if i wanted the animation to be played when i press a key would i just change ("Fire1") to ("w")?
Use the following for the X key:
Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.X);
Unity makes handling input remarkably easy on all devices:
http://unity3d.com/support/documentation/ScriptReference/Input.html
Your answer
Follow this Question
Related Questions
Blender animation 1 Answer
Stop animation after played 30 times? 0 Answers
Animation Problems 1 Answer
Trying to simply play this animation... Help please. 1 Answer