Press R To reload help!

using System.Collections;
using UnityEngine;

public class Gun : MonoBehaviour
{
public float damage = 10f;
public float range = 100f;
public float fireRate = 1f;

public int maxAmmo = 10;
private int currentAmmo;
public float reloadTime = 1f;
private bool isReloading = false;

public Animator animator;

public Camera fpsCam;

void Start()
{
currentAmmo = maxAmmo;
}

private float nextTimeToFire = 0f;

// Update is called once per frame
void Update()
{

if (isReloading)
return;

if (currentAmmo <= 0)
{
if(Input.GetKeyDown(KeyCode.R))
{
StartCoroutine(Reload());
return;
}
}

if (Input.GetMouseButton(0) && Time.time >= nextTimeToFire)
{
nextTimeToFire = Time.time + 1f/fireRate;
shoot();
}
}
IEnumerator Reload ()
{
isReloading = true;
Debug.Log(“Reloading…”);

animator.SetBool(“Reloading”, true);

yield return new WaitForSeconds(reloadTime - .25f);
animator.SetBool(“Reloading”, false);
yield return new WaitForSeconds(.25f);

currentAmmo = maxAmmo;
isReloading = false;
}

void shoot ()
{

currentAmmo–;

RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent();
if (target != null)
{
target.TakeDamage(damage);
}

}
}

}
hello. this is my gun script from brackeys yt and i wanna make it so when no ammo is true i want it to make the player have to hit r to reload other than just do it automaticaly

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

You may edit your post above.

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

You may edit your post above.