So I am using Brackey’s tutorial on reloading a gun, but I have run into a problem. Every time I start the game with the script below the Debug.Log("Reloading...")
continues to pop up in the console continuously even when I don’t shoot. That also means that even when I don’t press ‘R’ in the future, it will continuously reload. Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pistolShoot : MonoBehaviour {
public GameObject bullet;
public float showTime = 0.1f;
public AudioSource pistolSound;
public int maxAmmo = 15;
public float reloadTime = 2.148f;
private int currentAmmo;
void Start () {
if (currentAmmo == -1)
currentAmmo = maxAmmo;
bullet.SetActive (false);
}
void Reload() {
Debug.Log ("Reloading...");
currentAmmo = maxAmmo;
}
void Update () {
currentAmmo--;
if (currentAmmo <= 0) {
Reload ();
return;
}
if (Input.GetButtonDown ("Fire1")) {
StartCoroutine (bulletShoot ());
pistolSound.Play ();
}
}
IEnumerator bulletShoot() {
bullet.SetActive (true);
yield return new WaitForSeconds (showTime);
bullet.SetActive (false);
}
}