x


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.

more ▼

asked Sep 17 '11 at 07:13 PM

Dreave gravatar image

Dreave
122 82 94 96

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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();
    }
}
more ▼

answered Sep 17 '11 at 07:24 PM

jahroy gravatar image

jahroy
3.2k 14 18 41

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")?

Sep 17 '11 at 07:34 PM Dreave

Use the following for the X key:

Input.GetKeyDown(KeyCode.X);

Unity makes handling input remarkably easy on all devices:

http://unity3d.com/support/documentation/ScriptReference/Input.html
Sep 17 '11 at 07:37 PM jahroy

Thanks your the best!

Sep 17 '11 at 08:01 PM Dreave
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5064
x3772
x3725
x722
x446

asked: Sep 17 '11 at 07:13 PM

Seen: 3242 times

Last Updated: Sep 17 '11 at 08:01 PM