Esempio n. 1
0
 public void Reload()
 {
     //reloadTimer = (1f / reloadSpeed) + (.5f - (reloadSpeed / 10));
     if (currentMagazine < magazineSize)
     {
         int heldAmmo = playerAmmo.GetAmount(ammoType);
         reloadSpeed = playerProperties.handSpeed * reloadSpeedModifier;
         anim.SetTrigger("Reload");
         anim.SetFloat("Reload Speed", reloadSpeed);
         if (heldAmmo >= magazineSize)
         {
             playerAmmo.RemoveAmmo((int)magazineSize - (int)currentMagazine, ammoType);
             currentMagazine = magazineSize;
         }
         else if (heldAmmo > 0)
         {
             while (currentMagazine < magazineSize && heldAmmo > 0)
             {
                 currentMagazine++;
                 playerAmmo.RemoveAmmo(1, ammoType);
                 heldAmmo = playerAmmo.GetAmount(ammoType);
             }
         }
     }
 }
Esempio n. 2
0
        public void RangedAttack()
        {
            if (AttackSound.Count > 0)
            {
                AudioSource.PlayClipAtPoint(AttackSound.Random(), transform.position);
            }

            var bullet = Instantiate(Bullet);

            if (Tip != null)
            {
                var        ray = _viewCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
                RaycastHit hit;
                Vector3    dir;

                if (Physics.Raycast(ray, out hit))
                {
                    dir = (hit.point - Tip.transform.position).normalized;
                }
                else
                {
                    dir = _viewCamera.transform.forward;
                }

                bullet.transform.position = Tip.transform.position;
                bullet.transform.rotation = Quaternion.LookRotation(dir);
            }
            else
            {
                bullet.transform.position = transform.position;
                bullet.transform.rotation = transform.rotation;
            }

            bullet.GetComponent <Bullet>().Damage = Random.Range(1, 5);

            _lastShot = Time.fixedTime;
            _ammo.RemoveAmmo(AmmoType.Solution, 1);
        }