My gun reloading dont work,can i please get help.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class shoot : MonoBehaviour {
	
	public Rigidbody  bulletPrefab;
	public Transform  bulletSpawn;
	public float shootingSpeed;
	public int bulletAmmount;
    int shootedBulletAmmount;
	public int currentBulletAmmount;

	bool isSpawned;
	bool canShoot;

	void Start()
	{
		canShoot = true;
	}

	void Update()
	{
		Shoot ();
		Reload ();

	}

	void Shoot ()
	{
		if(canShoot==true)
		
		{
			if (Input.GetButtonDown ("Fire1")) {
		        
				shootedBulletAmmount = shootedBulletAmmount++;	    
				isSpawned = true;
				print (shootedBulletAmmount);			
				Rigidbody rocketInstance;
				rocketInstance = Instantiate (bulletPrefab, bulletSpawn.position,  bulletSpawn.rotation) as Rigidbody;
				rocketInstance.AddForce (bulletSpawn.forward * shootingSpeed);
		
		}
	}
	
}

	void Reload()

	{
		if(isSpawned==true)
		{
			currentBulletAmmount = bulletAmmount -= shootedBulletAmmount;

		}

		if (currentBulletAmmount <= 0) 
		{
			canShoot = false;
		}

		if (canShoot == false) 
		{
			StartCoroutine("readyShoot");
		}
   }

		  
		

	IEnumerator readyShoot()
	{
		yield return new WaitForSeconds (3);
		canShoot = true;
		bulletAmmount = 20;
		shootedBulletAmmount = 0;
		currentBulletAmmount = 0;

	}




}

Ok, so first of all it seems like your variable “isSpawned” doesn’t actually do anything, since it’ll always be “true” after the first shot… You could get rid of the first if statement on the Reload function and use simply like this:

     void Reload()
 
     {

         currentBulletAmmount = bulletAmmount -= shootedBulletAmmount;

 
         if (currentBulletAmmount <= 0) 
         {
             canShoot = false;
         }
 
         if (canShoot == false) 
         {
             StartCoroutine("readyShoot");
         }
    }

And I guess that your problem is on how you are doing the reload, since calling the function on the Update() all of the time should make you reload super fast and so it would not decrease your current number of bullets (I recommend associate a button press to it or reloading only when there are no more bullets)… Right? What exactly is happening?


oke i tried some different and it works… btw thx for help and waste ur time, but u helpeded me to learn some