Example #1
0
 void OnDestroy()
 {
     if (target != null)
     {
         target.ApplyDamage(damage);
     }
 }
    public Vector2 HandleBullet(Vector2 EndPoint, RaycastHit2D[] RCH, Collider2D[] IgnoreColliders)
    {
        foreach (RaycastHit2D Hit in RCH)
        {
            if (Hit.collider != null)
            {
                if (IgnoreColliders.Contains(Hit.collider))
                {
                    continue;
                }

                IDamagable Char = Hit.collider.GetComponent <IDamagable>();

                if (Char != null)
                {
                    bool stop = Char.StopsBullet;

                    Char.ApplyDamage(WeaponConfiguration.Damage);

                    if (stop)
                    {
                        return(Hit.point);
                    }
                }
            }
        }

        return(EndPoint);
    }
        /// <summary>
        /// Checks for an IDamagable on the target GameObject, then attempts to call its ApplyDamage method.
        /// If an IDamagable isn't found, returns false.
        /// </summary>
        /// <param name="damageTarget"> The Target to look for an IDamagable on.</param>
        /// <param name="e"> Damage Event Arguments.</param>
        /// <returns></returns>
        public virtual bool TryDealDamage(GameObject damageTarget, Damage.DamageEventArgs e)
        {
            if (!CanDealDamage)
            {
                return(false);
            }
            if (e.DamageValue <= 0)
            {
                return(false);
            }
            IDamagable damagable = damageTarget.GetComponent <IDamagable>();

            if (damagable != null)
            {
                if (this.faction == damagable.GetFaction())
                {
                    return(false);
                }
                damagable.ApplyDamage(this, e);
                OnDealDamage(this, e);
                return(true);
            }
            // No IDamagable Found - Return false.
            return(false);
        }
Example #4
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        IDamagable component = (IDamagable)other.GetComponent(typeof(IDamagable));

        if (component != null && !other.CompareTag(TagContainer.Player_Tag))
        {
            component.ApplyDamage(10);
        }
    }
Example #5
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        IDamagable component = other.gameObject.GetComponent <IDamagable>();

        if (component != null)
        {
            Destroy(other.gameObject);
            component.ApplyDamage();
        }
    }
Example #6
0
 private void ApplyDamage(IDamagable damagable)
 {
     if (damagable is Shield)
     {
         (damagable as Shield).ApplyDamage(_damage, _blastRadius);
     }
     else
     {
         damagable.ApplyDamage(_damage);
     }
 }
Example #7
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        IDamagable component = (IDamagable)other.GetComponent(typeof(IDamagable));

        if (component != null && !other.CompareTag(TagContainer.Player_Tag))
        {
            component.ApplyDamage(1);
            Destroy(gameObject);
        }
        else if (other.CompareTag(TagContainer.Top_Border))
        {
            Destroy(gameObject);
        }
    }
Example #8
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        IDamagable component = other.GetComponent <IDamagable>();

        if (component != null)
        {
            Destroy(other.gameObject);
            component.ApplyDamage();
        }

        if (other.CompareTag(TagContainer.BOMB_TAG))
        {
            Bomb tmp = other.gameObject.GetComponent <Bomb>();
            tmp.ApplyDamage();
        }

        if (other.CompareTag(TagContainer.PORTAL_TAG))
        {
            CustomEventSystem.PortalExplosionAction(transform.position);
        }
    }
Example #9
0
 void Update()
 {
     damageThis.ApplyDamage(damagePerSecond * Time.deltaTime);
 }
Example #10
0
 public static void ApplyDamage(IDamager damager, IDamagable damagable)
 {
     damagable.ApplyDamage(damager.GetDamage(), new Vector2(0, 0));
 }
Example #11
0
 public static void ApplyDamage(IDamager damager, IDamagable damagable, Vector2 velocity)
 {
     damagable.ApplyDamage(damager.GetDamage(), velocity);
 }