Ejemplo n.º 1
0
 private void TryShoot()
 {
     if (Application.platform == RuntimePlatform.Android || Input.GetMouseButton(0))
     {
         if (Time.time - _lastShot > _rateOfFire && _currentAmmoCount > 0)
         {
             Ray        ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width * 0.5f, Screen.height * 0.5f));
             RaycastHit hit;
             Physics.Raycast(ray, out hit);
             if (Application.platform != RuntimePlatform.Android || hit.transform.tag == "Damageable")
             {
                 // this can me null if firing in sky on PC
                 if (hit.collider)
                 {
                     Instantiate(_hitParticle, hit.point, Quaternion.identity);
                     EntityHealth component = hit.collider.GetComponent <EntityHealth>();
                     if (component)
                     {
                         component.TakeDamage(_damage);
                     }
                     else
                     {
                         // Only spawn decal on non damageable entities (IE walls, ground)
                         Instantiate(_decalPrefab, hit.point + hit.normal * A_LITTLE_FORWARD, Quaternion.LookRotation(-hit.normal));
                     }
                 }
                 _lastShot = Time.time;
                 if (!_infiniteAmmoActivated)
                 {
                     CurrentAmmoCount--;
                 }
                 if (_currentAmmoCount == 0)
                 {
                     StartCoroutine("Reload");
                 }
                 // Feedbacks
                 // randomize pitch to avoid the sound so be all time the same
                 _shotAudioSource.pitch = UnityEngine.Random.Range(1f, 1.1f);
                 _shotAudioSource.PlayOneShot(_gunSound);
                 _muzzleFlashAnimator.SetTrigger("Fire");
                 StartCoroutine(_cameraShake.Shake(_shakeDuration, _shakeMagnitude));
             }
         }
     }
     if (_currentAmmoCount < _MaxAmmo)
     {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             // PC reload
             StartCoroutine("Reload");
         }
         if (Input.acceleration.magnitude > _mobileAccelerationMagnitudeToReload)
         {
             // mobile reload
             StartCoroutine("Reload");
         }
     }
 }
Ejemplo n.º 2
0
 private void DoBombDamage(EntityHealth enemy, int damage)
 {
     enemy.TakeDamage(damage, IDofLastHit);
     if (enemy.GetHealth() - damage <= 0)
     {
         EventController.FireEvent(new TrackSuperlativeMessage(SuperlativeController.Superlative.HailMary,
                                                               SuperlativeController.ConditionFlag.identity, Vector3.Distance(transform.position, GetComponent <BallRetrieval>().GetLastPos()),
                                                               GetLastShotId()));
     }
 }
Ejemplo n.º 3
0
        private void Shoot(Cell target)
        {
            if (target.FrontEntity == null)
            {
                return;
            }

            EntityHealth health = target.FrontEntity.GetComponent <EntityHealth>();

            health.TakeDamage(GetDamage());
        }
Ejemplo n.º 4
0
    public override void TriggerAbilityPlayer(Collider other)
    {
        EntityHealth enemy = other.gameObject.GetComponent <EntityHealth>();

        if (enemy)
        {
            enemy.TakeDamage(damage, IDofLastHit);
            if (enemy.GetHealth() - damage <= 0)
            {
                EventController.FireEvent(new TrackSuperlativeMessage(SuperlativeController.Superlative.HailMary,
                                                                      SuperlativeController.ConditionFlag.identity, Vector3.Distance(transform.position, GetComponent <BallRetrieval>().GetLastPos()),
                                                                      GetLastShotId()));
            }
        }

        base.TriggerAbility();
    }