x


Activating an Animation?

I am trying to make a js script that will play an animation when "Fire1" is pressed. I am not sure how to write that kind of script. Could someone please share a full code with me on how to do that?

more ▼

asked May 29 '10 at 06:12 AM

0V3RWR173D gravatar image

0V3RWR173D
190 10 11 25

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

2 answers: sort voted first

Two steps: First, check for the fire button. Second, activate an animation.

So create a script, and in the Update function that's placed in there, add the following:

  if (Input.GetButtonDown ("Fire1")){
    // runs this code when the fire button is pressed down
    animation.Play();  // this will play the default animation on this object
  }

This script assumes that the animation in question is on the same object as the script, if not then you need to link to the target object with a variable.

For more detail on any function, select or type its name in the code editor and press F1. This brings up the Unity Reference for explanation and examples of the classes and functions.

more ▼

answered May 29 '10 at 09:06 AM

Novodantis 1 gravatar image

Novodantis 1
1.7k 14 22 40

can you tell me where i can find a whole script for this... i tried making a new script of this and put it on my sniper but it doesn't work, the sniper plays the animation when i start playing but not when i shoot?

Jun 23 '10 at 06:28 AM user-3180 (yahoo)
(comments are locked)
10|3000 characters needed characters left

so i found this post while searching for advice with my script, i have two different object each with animations on them and i want each of them to play there animations when fire1 is pressed. but when i give the objects this code they both play when i click on one, how do i change it so i can use the same code but have it so that only when you click on the specific object then it plays the animation?

How would you implement this in the above script?

more ▼

answered May 31 '12 at 10:46 AM

Dysengaged gravatar image

Dysengaged
2 1 3 8

(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:

x5085
x3792
x3460
x79
x5

asked: May 29 '10 at 06:12 AM

Seen: 2726 times

Last Updated: May 31 '12 at 10:46 AM