Play Animation on Click c# Unity 5.2
using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
public GameObject bullet;
public float delayTime = 8;
private float counter = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if(Input.GetKeyDown(KeyCode.Mouse0) && counter > delayTime)
{
Instantiate(bullet, transform.position, transform.rotation);
counter = 0;
}
counter += Time.deltaTime;
}
}
That is my code for my gun shooting. The script is connected to an Empty that produces the bullet on click. I want to be able to play the animation of the gun only once on key press, but I have no clue on how to do it now.
I have tried following this as it seems the most simplse: http://answers.unity3d.com/questions/165833/play-animation-on-button-press.html
The problem arises when I get the error of CS0619 when I try putting animation.Play("shooting");
I appreciate any help and advice as I have little to no experience in coding and is just following tutorials online.
Your answer
![](https://koobas.hobune.stream/wayback/20220612035950im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Animation Help! 1 Answer
Why is scripting animation not so responsive in unity? 0 Answers
Any Clue why this is turning 180? 2 Answers
How to modify a value after the animation is done with it. 0 Answers
Interpolated movement in a circle 1 Answer