#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;
function Start()
{
GetComponent.().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.().Play("Reload",PlayMode.StopAll);
Reload();
Ammo = 0;
}
else
{
if (timestamp <= Time.time && Physics.Raycast (ray, hit, 10))
{
timestamp = Time.time + delay;
if(hit.collider.gameObject.tag == "Dobj")
{
Ammo--;
GetComponent.().Play("Fire",PlayMode.StopAll);
GetComponent.().Play();
hit.transform.SendMessage("ApplyDammage", theDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
function Reload()
{
yield WaitForSeconds(1.8);
Ammo = MaxAmmo;
Rounds--;
Reloading = false;
}
When the gun reloads the value of rounds goes in negative............... please update this for reloading the gun perfectly ................thanks in advance
↧