Hi all, I have wrote this script that spawns a simple particle effect of a muzzle flash at the end of my gun when the LMB is clicked, I have other scripts on my gun that control shooting raycasts and reloading ect, but I’m having a problem with how I would stop the muzzle flash for being able to be spawned when the gun is reloading, I have done so with my raycasts and animations but I don’t know how I would do it for this, can anyone help me out please?
As I said. You should add a reload variable to keep track of if you are reloading or not. Here is something to help you along the way:
var muzzleFlash : GameObject;
var spawnPoint : Transform;
var amountOfShots = 8;
var reloadTime = 1.5;
private var reloading = false;
function Update (){
if(Input.GetButtonDown("Fire1") && !reloading){ //Check for input and that we aren't reloading
//Exclamation mark pretty much means "is false"
Shoot();
}
}
if(Input.GetKeyDown("r")){
Reload();
}
function Reload (){
reloading = true; //Set reloading to true because... We are reloading
yield WaitForSeconds(reloadTime);
amountOfShots = 8;
reloading = false; //Set reloading to false because we are done reloading
}
function Shoot (){
//All of this below will now only execute when we are not reloading
if(amountOfShots > 0){ //If we have ammunition left
amountOfShots--;
Instantiate(muzzleFlash, spawnPoint.position, spawnPoint.rotation);
}
}
Not tested, but might work and you should be able to get an idea of what to do.