Adding muzzle flash to the gun....
I Want to add a muzzle flash to the gun the gun automatically fires if the gun aims on enemy......
#pragma strict
var Rounds : int;
var Ammo : int;
var Reloading : boolean;
var MaxAmmo : int = 20;
var theDammage = 100;
var delay = 0.1;
var timestamp = 0.0;
var ReloadTime = 1.8;
private var reloading : boolean = false;
function Start()
{
GetComponent.<Animation>().Play("Idle",PlayMode.StopAll);
%|-841674305_1|%
function Update ()
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if(Rounds == 0 && Ammo == 0 )
{
return;
}
if (Ammo <= 0 && Rounds >= 0 )
{
Reloading = true;
GetComponent.<Animation>().Play("Reload",PlayMode.StopAll);
Reload();
}
else
{
if (timestamp <= Time.time && Physics.Raycast (ray, hit, 10) && Reloading == false)
{
timestamp = Time.time + delay;
if(hit.collider.gameObject.tag == "Dobj")
{
Ammo--;
GetComponent.<Animation>().Play("Fire",PlayMode.StopAll);
GetComponent.<AudioSource>().Play();
hit.transform.SendMessage("ApplyDammage", theDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
function Reload()
{
yield WaitForSeconds (1);
if(Ammo == 0 && !Reloading)
{
Rounds --;
Reloading = true;
Ammo = MaxAmmo;
}
Reloading = false;
}
thanks in advance.........I am not using particle renderer ...i am using A simple plane`
Answer by $$anonymous$$ · Mar 04, 2017 at 01:14 PM
what you could do is have a point light at the very front of the barrel as well as maybe a particle system. (Add a flare to make it realistic). Make them as children so they follow the barrel where ever it goes.
Since you seem quite knowledgeable in animation I'd suggest using an animation that turns the light on for a set amount of time meaning you would not need to turn off the light through script(Which would suck).. so then all you'd have to do is
GetComponentInChildren().Play("LightFlash");
Sorry my input isn't more code handy but since i have no clue what your setup is or do i use your programming language natively i can't help too much.
Your answer
Follow this Question
Related Questions
Adding muzzle flash to the unity 0 Answers
fireRate javascript? 1 Answer
Having trouble getting fps gun(s) too shoot please help me out now 2 Answers
Ammo Script 0 Answers