- Home /
Question by
unity_dVYhPoANmMYl4g · May 26, 2020 at 03:50 PM ·
fpsfpscontrollerfps tutorial
,Wait for animation
Hi. I'm doing a simple fps, and as you can see from the code, once you click the left mouse button, the animation starts.
The problem is this: if I click quickly in the game, the animation starts again as many times. How can I make you wait to shoot again?
this is my code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Shooting : MonoBehaviour { public GameObject bulletImpact; //per gestire l'impatto del proiettile public Camera mainCam; public int currentAmmo; //proiettili
public Animator gunAnimation;
public Animation shoot;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//mouseButton 0 = click sinistro
if (Input.GetMouseButtonDown(0))
{
if (currentAmmo > 0)
{
Ray ray = mainCam.ViewportPointToRay(new Vector3(.5f, .5f, .0f));
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Debug.Log("Sto guardando a: " + hit.transform.name);
Instantiate(bulletImpact, hit.point, transform.rotation);
}
else
{
Debug.Log("Non sto guardando niente");
}
currentAmmo--; //diminuisce proiettili
gunAnimation.SetTrigger("Shoot");
//how can I wait?
}
}
}
},
Comment
Your answer
Follow this Question
Related Questions
how do i disable fps controler 0 Answers
FPS Tutorial problem 1 Answer
Unity Effect 1 Answer
[NEED HELP ASAP!] Where do I put the GvrViewerMain in my FPS VR Multiplayer project? 0 Answers