- Home /
Muzzle flash help
I wrote a script telling a muzzle flash particle effect to spawn when someone clicks the left mouse button, it has the same variables as my raycasts which act as bullets this is so the muzzle flash can only play 8 times before having to reload.
This all worked fine for my pistol which shoots only once when the left mouse button has been clicked, but now I am trying to do the same thing for my machine gun which fires constantly until the mouse button has been let go of. I have tried changing my script but have had no luck, can someone help me out with this please?
This is my altered script (has no errors)
var muzzleFlash : GameObject;
var spawnPoint : Transform;
var fullClip : int = 30;
var bulletsLeft : int = 30;
var waitTime = 1.5;
var refireRate : float = 0.1;
function ShotPoller () {
while(true)
{
if(Input.GetButton("Fire1"))
{
Shoot();
yield WaitForSeconds(refireRate);
}
if(Input.GetKeyDown("r")){
Reload();
}
yield;
}
}
function Start(){
StartCoroutine(ShotPoller());
}
if(Input.GetButtonDown("r")){
Reload();
}
function Shoot () {
if(Input.GetButtonDown("Fire1")){
if(bulletsLeft > 0 ){
bulletsLeft -- ;
Instantiate(muzzleFlash, spawnPoint.position, spawnPoint.rotation);
}
}
}
function Reload () {
if(Input.GetButtonDown("r")){
yield WaitForSeconds(waitTime);
bulletsLeft = fullClip;
}
}
What's wrong with machinegun muzzle flash?
It might be easier to get rid of all the reload/input code from muzzle flash. Ins$$anonymous$$d, only the bullets worry about that, and they "fire" a muzzle flash for each bullet.
What happens is my muzzle flash only plays once when you click the left mouse button, I want it to keep playing the muzzle flash until the left mouse button has stop being held down.
Answer by Griffo · Mar 16, 2013 at 05:48 PM
Just change your line -
if(Input.GetButtonDown("Fire1")){
to -
if(Input.GetButton("Fire1")){
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Gun Muzzle Flash 2 Answers
How do I make a raycast for a particle 1 Answer
damage cooldown 1 Answer
Custom Collision Detection 4 Answers