Beispiel #1
0
        protected void OnTriggerEnter2D(Collider2D other)
        {
            IDamageReceiver damageReceiver = other.GetComponent <IDamageReceiver>();

            if (damageReceiver != null)
            {
                //Debug.Log("Hit a damage receiver.");
                // Check if the other GameObject is a PlayerSpaceship.
                if (other.gameObject.GetComponent <PlayerSpaceship>() != null)
                {
                    // If it is, check if it is immortal.
                    if (!other.gameObject.GetComponent <PlayerSpaceship>()._isImmortal)
                    {
                        damageReceiver.TakeDamage(GetDamage());
                    }
                }
                else
                {
                    damageReceiver.TakeDamage(GetDamage());
                }
            }
            if (!_weapon.DisposeProjectile(this))
            {
                Debug.LogError("Couldn't dispose projectile.");
                Destroy(gameObject);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Called when the projectile collides with something.
        /// </summary>
        /// <param name="collision">Collision info</param>
        protected void OnCollisionEnter(Collision collision)
        {
            if (!Destroyed)
            {
                //ApplyDamage();
                IDamageReceiver dmgRec = collision.transform.GetComponent <IDamageReceiver>();
                if (dmgRec != null)
                {
                    dmgRec.TakeDamage(damage);
                }

                // Stops the projectile
                Rigidbody.velocity = Vector3.zero;

                // Passes collision information to the weapon
                PassCollisionInfoToWeapon(this);

                // Creates a hit mark at the point of impact
                //if (!hitMarkCreated)
                //{
                //    CreateHitMark(collision);
                //    hitMarkCreated = true;
                //}

                DestroyObject();
            }
        }
Beispiel #3
0
    private void SendDamage(Collider other)
    {
        IDamageReceiver receiver = other.transform.GetComponent <IDamageReceiver>();

        if (receiver != null)
        {
            receiver.TakeDamage(10);
        }
    }
Beispiel #4
0
        public HealthModifier(IDamageReceiver _receiver, TankType _damageType)
        {
            if (_receiver == null)
            {
                return;
            }
            var damagePoint = TableService.Instance.GetDamagePoint(_damageType);

            _receiver.TakeDamage(damagePoint);
        }
Beispiel #5
0
 protected virtual void OnHit(GameObject hitObj, Vector3 hitPosition)
 {
     if (hitObj != null)
     {
         //Debug.Log("Hit " + hitObj.name);
         IDamageReceiver dmgRec = hitObj.transform.GetComponent <IDamageReceiver>();
         if (dmgRec != null)
         {
             dmgRec.TakeDamage(GetDamage());
         }
     }
 }
Beispiel #6
0
        protected void OnTriggerEnter2D(Collider2D other)
        {
            IDamageReceiver damageReceiver = other.GetComponent <IDamageReceiver>();

            if (damageReceiver != null)
            {
                damageReceiver.TakeDamage(GetDamage());
            }
            if (_Weapon.DisposePrjectile(this) == false)
            {
                Destroy(this.gameObject);
                Debug.LogError("Error in disposing projectile");
            }
        }
Beispiel #7
0
        private void ApplyDamage()
        {
            List <IDamageReceiver> alreadyDamaged = new List <IDamageReceiver>();

            Collider[] damageReceivers = Physics.OverlapSphere(transform.position, explosionRadius, _hitMask);
            for (int i = 0; i < damageReceivers.Length; i++)
            {
                IDamageReceiver damageReceiver = damageReceivers[i].GetComponentInParent <IDamageReceiver>();
                if (damageReceiver != null && !alreadyDamaged.Contains(damageReceiver))
                {
                    alreadyDamaged.Add(damageReceiver);
                    damageReceiver.TakeDamage(_damage);
                }
            }
        }
        protected void OnTriggerEnter2D(Collider2D other)
        {
            IDamageReceiver damageReceiver = other.GetComponent <IDamageReceiver>();

            if (damageReceiver != null)
            {
                damageReceiver.TakeDamage(GetDamage());
            }

            if (!_weapon.DisposeProjectile(this))
            {
                Debug.LogError("Could not return the projectile back to the pool!");
                Destroy(gameObject);
            }
        }
Beispiel #9
0
        protected void OnTriggerEnter2D(Collider2D other)
        {
            IDamageReceiver damageReceiver = other.GetComponent <IDamageReceiver>();

            if (damageReceiver != null)
            {
                Debug.Log("Damage taken!");
                damageReceiver.TakeDamage(GetDamage());
                //ToDo Return projectile back to pool.
                throw new System.NotImplementedException("Return projectile to the pool");
                //Destroy(gameObject);
            }
            if (_weapon.DisposeProjectile(this) == false)
            {
                Debug.LogError("Could no return the projectile back to the pool.");
                Destroy(gameObject);
            }
        }
        private void ApplyDamage()
        {
            List <IDamageReceiver> alreadyDamaged = new List <IDamageReceiver>();

            Collider[] damageReceivers = Physics.OverlapSphere(transform.position,
                                                               _explosionRadius, _hitMask);
            for (int i = 0; i < damageReceivers.Length; ++i)
            {
                IDamageReceiver damageReceiver =
                    damageReceivers[i].GetComponentInParent <IDamageReceiver>();
                // Did we found a damage receiver? If yes, apply damage if not done already.
                if (damageReceiver != null && !alreadyDamaged.Contains(damageReceiver))
                {
                    damageReceiver.TakeDamage(_damage);
                    alreadyDamaged.Add(damageReceiver);
                    // TODO: Apply explosion force
                }
            }
        }
Beispiel #11
0
    private void Hit(Collider hitCollider)
    {
        IDamageReceiver damageReceiver = hitCollider.GetComponent <IDamageReceiver>();

        if (damageReceiver != null)
        {
            damageReceiver.TakeDamage(Damage);
            ReturnProjectile();
        }
        else //if (1 << hitCollider.gameObject.layer == (int) Const.Layers.Environment || 1 << hitCollider.gameObject.layer == (int) Const.Layers.Activator || 1 << hitCollider.gameObject.layer == (int) Const.Layers.InvisibleWall)
        {
            ActivatorBase activator = hitCollider.GetComponent <ActivatorBase>();
            if (activator != null)
            {
                activator.Active = true;
            }
            ReturnProjectile();
        }
    }
Beispiel #12
0
        protected void OnTriggerEnter2D(Collider2D other)
        {
            IDamageReceiver damageReceiver =
                other.GetComponent <IDamageReceiver>();

            if (damageReceiver != null)
            {
                // Inflicts damage to the target
                damageReceiver.TakeDamage(GetDamage());

                if (!weapon.DisposeProjectile(this))
                {
                    Debug.LogError("Could not return the projectile to the pool.");

                    // Destroys the projectile
                    Destroy(gameObject);
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Deals damage to the hit target.
        /// </summary>
        private void ApplyDamage()
        {
            List <IDamageReceiver> alreadyDamaged = new List <IDamageReceiver>();

            // Gets all damage receiving colliders in
            // an area within the explosion radius
            Collider[] damageReceivers = Physics.OverlapSphere(
                transform.position, explosionRadius, hitMask);

            // Deals damage to the damage receivers if they are valid
            for (int i = 0; i < damageReceivers.Length; i++)
            {
                IDamageReceiver damageReceiver =
                    damageReceivers[i].GetComponentInParent <IDamageReceiver>();
                if (damageReceiver != null &&
                    !alreadyDamaged.Contains(damageReceiver))
                {
                    damageReceiver.TakeDamage(damage);
                    alreadyDamaged.Add(damageReceiver);
                    // TODO: Apply explosion force
                }
            }
        }
Beispiel #14
0
 private void ApplyDamage(IDamageReceiver damageReceiver)
 {
     damageReceiver.TakeDamage(_damage);
 }