- Home /
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?
Answer by Novodantis 1 · May 29, 2010 at 09:06 AM
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.
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?
Answer by Dysengaged · May 31, 2012 at 10:46 AM
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?
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Animation scripting. 1 Answer
Unity model scripting question 1 Answer
Need help with sprite animating 1 Answer