Exemplo n.º 1
0
    //Reload the weapon
    public void CallReload()
    {
        //Do we need to reload, and do we can ?
        if (currentAmmo < maxAmmoPerMagazine && currentMagazine > 0 && Time.time - lastAction >= timeBeforeNextShoot)
        {
            lastOutput = ShootOutput.RELOAD;

            //To not deal with 2 variables, we set the time that triggers the last action at timeReload and not timeBNS
            lastAction = Time.time + timeReload - timeBeforeNextShoot;
            StartCoroutine(Reload());
        }
        else
        {
            lastOutput = ShootOutput.FAILED;
        }
    }
Exemplo n.º 2
0
 public ShootOutput Shoot()
 {
     //If the weapon is not automatic, it needs to be release each time
     if (!isAutomatic() && triggerPulled)
     {
         lastOutput = ShootOutput.FAILED;
     }
     else
     {
         triggerPulled = true;
         if (Time.time - lastAction < timeBeforeNextShoot) //If we call a shoot before the next action it failed
         {
             lastOutput = ShootOutput.FAILED;
         }
         else
         {
             if (currentAmmo == 0)
             {
                 //If the current ammo are 0 but there's still magazine, we call reload
                 if (currentMagazine > 0)
                 {
                     CallReload();
                 }
                 else
                 {
                     //Else, the weapon is empty
                     lastOutput = ShootOutput.EMPTY;
                 }
             }
             else
             {
                 //Lost an ammo when the shoot is valid
                 currentAmmo--;
                 lastAction = Time.time;
                 lastOutput = ShootOutput.VALID;
                 sendBullet();
             }
         }
     }
     return(lastOutput);
 }