- Home /
Making an animation start when my gun fires
Hi,Im trying to make my machine gun have sort of a recoil effect I have animated the gun but how do I only make play when i have shot the gun? Can anyone point me to a tutorial or tell me how
-thanks!
Answer by StephanK · Jun 14, 2010 at 08:14 PM
animation.Play(nameOfAnimationClip);
This is ok but what script do insert this to sorry im a unity nwb but i do understand javascript very well. BTW i am using the fps tutorial.
This needs to be attached to the GameObject that contains the Animation component of the gun. You could also insert code to the script that actually fires the gun and then call a function of the script attached to the gun.
this doesnt work for me, when i write the name of the animation in the script it "says unknown identifier "Shoot"" help please?
You probably wrote it without "". The call in your case would look like this: animation.Play("Shoot");
Answer by user-11096 (google) · Apr 21, 2011 at 02:00 AM
Well you got your script right, wellt under the FireOneShot function (if you have one)
example of the FireOnShot Code
function FireOneShot () { var direction = transform.TransformDirection(Vector3.forward); animation.Play("Fire Shot") var hit : Raycasthit;
if(Physics.Raycast (transform.position, direction, hit, range))
{
if (hit.rigidbody)
hit.rigidbody.AddForceAtPosition(force * direction hit.point);
if(hitParticles)
{
hitParticles.transform.position = hit.point;
hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
hitParticles.Emit();
}
hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReciever);
}
}
This is the shoot function for my script. Pretty confusing huh.
Your answer
Follow this Question
Related Questions
Gun Animate when it shoots 3 Answers
Animations at every shot? 2 Answers
Gun and hand animation tutorial! 2 Answers
Animation plays at original position? 1 Answer
Shooting & Animation Problem 1 Answer