How do I make a gun stop playing a shoot animation when I release the fire button? Heres my code:
I need help with my code!! Im making an first person shooter and this is my code: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class GunFire : MonoBehaviour {
void Update() { if (Input.GetButtonDown("Fire1")) { AudioSource gunsound = GetComponent(); gunsound.Play(); GetComponent().Play("GunShot"); } } }
when I press the fire button the animation plays, but it keeps going, and I cant stop it! What do I do? Also, the audio clip I attached to it stops but I want it to play when the firing animation plays and stop after a point in time
public class GunFire : MonoBehaviour {
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
AudioSource gunsound = GetComponent<AudioSource>();
gunsound.Play();
GetComponent<Animation>().Play("GunShot");
}
}
}
Heres the raw code
Your answer
Follow this Question
Related Questions
Don't know how to end animation of shooting ! (code) Please help ! 0 Answers
What reason could there be, if a parent object refuses to take the new given position? 0 Answers
Animator Position VS Script Vector 3 0 Answers
Please help me with my shooting script. 0 Answers
Making your ai attack then return to the navmesh when player leaves trigger 0 Answers