Hey, I’m trying to get my gun to fire as a machine gun would. I can’t see what is wrong with my code so I hope somebody here can!
public float fireRate=0.5f;
public float nextFire=0.0f;
void Update () {
if(gun.active)
{
if(Input.GetMouseButton(0)&&Time.deltaTime>nextFire){
Debug.Log("shot fired");
nextFire = Time.deltaTime+fireRate;
audio.Play();
Ray ray=Camera.main.ScreenPointToRay(shootingPoint);
RaycastHit hit=new RaycastHit();
if(Physics.Raycast(ray,out hit))
{
if(hit.collider.gameObject.tag=="barrel")
..........................
So that is the main code I believe is causing problems. Sometimes the gun fires as soon as it is picked up without pressing the mouse button. Perhaps Input.GetMouseButton(0)is wrong as i changed that from Input.GetMouseButtonDown(0)?