Exemplo n.º 1
0
        private bool CanFire()
        {
            var ammunitionIsNotEmpty = (AmmunitionType == AmmoType.Infinite || _ammo.HasAmmo(AmmunitionType, 1));
            var itHasBeenLongEnoughSinceTheLastShot = Time.fixedTime - _lastShot > ShotDelay;

            return(ammunitionIsNotEmpty && itHasBeenLongEnoughSinceTheLastShot);
        }
Exemplo n.º 2
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         if (!reloading && playerAmmo.HasAmmo())
         {
             Fire();
         }
     }
     if (Input.GetKeyDown(KeyCode.R) && reloading == false && playerAmmo.currentAmmo < playerAmmo.startingAmmo)
     {
         Reloading();
         //muzzleFlash.GetComponent<Animation> ().Play ();
     }
     if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit))
     {
         ToDistance = hit.distance;
         Game.TargetFromDistance = ToDistance;
     }
 }
Exemplo n.º 3
0
    void Shoot()
    {
        if (!playerAmmo.HasAmmo())
        {
            return;
        }

        playerAmmo.UseAmmo();

        timer = 0f;

        gunAudio.Play();

        gunLight.enabled = true;

        gunParticles.Stop();
        gunParticles.Play();

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
            if (enemyHealth != null)
            {
                enemyHealth.TakeDamage(damagePerShot, shootHit.point);
            }
            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }