Question by
JIME363 · Mar 05, 2017 at 03:34 PM ·
gunfiremuzzleflash
Adding muzzle flash to the unity
#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);
}
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;
}
I Want to add a muzzle flash to the gun the gun automatically fires if the gun aims on enemy......thanks in advance.........I am not using particle renderer ...i am using A simple plane
Comment
Your answer
Follow this Question
Related Questions
Adding muzzle flash to the gun.... 1 Answer
Having trouble getting fps gun(s) too shoot please help me out now 2 Answers
Ammo Script 0 Answers
fireRate javascript? 1 Answer