- Home /
Reloading delay problem..
  #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.<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();
  Ammo = 0;
  }
  else
  {
  if (timestamp <= Time.time && Physics.Raycast (ray, hit, 10))
  {
   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.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
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Reload help 1 Answer
How to reload a gun with delay ? 2 Answers
i need to delay an action but my code isnt working 1 Answer
How do I put a delay on a gunshot? 2 Answers
Reloading A Gun My Way 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                