How to prevent a Void method from happening?,How to prevent a void from working in the script.

In the unity project that I am working on, there is a issue where when I am reloading my weapon I can still shoot while its happening, in a Coroutine, public void, private void method.
Whenever I press my LMB my shoot method occurs, is there a way to prevent a method from happening during these coroutines or when other methods are occurring so that I don’t shoot the weapon?

I’m not that new to English so apologies if the wording is confusing.,In my Unity project that I am working on there is a issue where I can still shoot while reloading.

I need it so that when this Coroutine is happening or Method that I cannot be able to use the void method for shooting to happen

Well, this really has nothing to do with “void methods”, I think you just want to prevent certain method calls during the execution of the coroutine, you can always use a bool value to control:

private bool _processing = false;

private IEnumerator LoadGun()
{
    // Maybe you also want to prevent the coroutine itself from being called repeatedly
    if (_processing) yield break;
    _processing = true;

    // Something ...

    _processing = false;
}

private void Shoot()
{
    if (_processing) return;
    // Something ...
}

It was asked here:

Seems the best way is to keep track of it with a bool, which is what I would do, you could make one bool canCallMethod and set it to true when coroutine is done and where you call your method you check if you can call it 1st, or you can use a return statement in beginning of the method itself if(!canCallMethod) return;

@logicandchaos is right (as usual)… I often see the following kind of structure in my students’ projects and it works quite nicely.

using System.Collections;
using UnityEngine;

public class Test2 : MonoBehaviour
{
	bool canShoot = true;

	void Update()
	{
		if (Input.GetMouseButtonDown(0) && canShoot)
		{
			// Call Shoot method
		}
	}

	void Reload()
	{
		canShoot = false;
		delayShoot(2);

		// Reload code
	}

	void ChangeWeapon()
	{
		canShoot = false;
		delayShoot(3);

		// Change Weapon code
	}

	IEnumerator delayShoot(float delayTime)
	{
		yield return new WaitForSeconds(delayTime);
		canShoot = true;
	}
}

You’ll see that you can use the same delayShoot Coroutine used for both changing weapon and reloading.