コード例 #1
0
    protected override void DamageTarget(Base_Health otherHealth)
    {
        if (!canDamage)
        {
            return;
        }
        //DAMAGE
        float maxDist = collider.radius * transform.localScale.x;
        float dist    = Vector3.Distance(transform.position, otherHealth.transform.position);
        float value   = (maxDist - dist) / maxDist;

        if (value <= 0f)
        {
            return;
        }
        {
            Rigidbody2D otherBody = otherHealth.GetComponent <Rigidbody2D> ();

            Vector2 diff = (maxDist - dist / maxDist) * (damage * (otherBody.position - mBody.position).normalized) * .25f;
            otherBody.AddForce(diff, ForceMode2D.Impulse);
        }

        int _id = id;

        if (otherHealth.GetPlayerTag().Id == id)
        {
            _id = -1;
        }

        otherHealth.TakeDamage(damage * (value), _id, team);
        excludeObjects.Add(otherHealth.gameObject);
    }
コード例 #2
0
    void OnTriggerStay2D(Collider2D other)
    {
        if (!canAttack)
        {
            return;
        }
        Base_Health health = other.GetComponent <Base_Health> ();

        if (health != null)
        {
            if (health.GetPlayerTag().Id != playerTag.Id && (health.GetPlayerTag().Team == 0 || health.GetPlayerTag().Team != playerTag.Team))
            {
                if (health.Health - damage <= 0f)
                {
                    if (other.GetComponent <Player_Health> () != null)
                    {
                        for (int i = 0; i < skeelAmount; i++)
                        {
                            GameObject skeel = Instantiate(skeelPrefab, other.transform.position, Quaternion.identity);
                            skeel.GetComponent <Mob_Skeel> ().Ini(null, playerTag.Id, playerTag.Team, true);
                        }
                    }
                }
                health.TakeDamage(damage, playerTag.Id, playerTag.Team);
                StartCoroutine(AttackCooldown());
            }
        }
    }
コード例 #3
0
    protected virtual void DamageTarget(Base_Health otherHealth)
    {
        if (!canDamage)
        {
            return;
        }
        //DAMAGE
        otherHealth.SetKillFlag(killFlag);
        otherHealth.TakeDamage(damage, id, team);

        /*
         * Rigidbody2D otherBody = otherHealth.GetComponent<Rigidbody2D> ();
         * float angle = transform.rotation.eulerAngles.z;
         * otherBody.AddForce (new Vector2(Mathf.Cos (angle * Mathf.Deg2Rad),Mathf.Sin(angle * Mathf.Deg2Rad)) * damage * .25f, ForceMode2D.Impulse);
         */
//FX
        if (deathParticlePrefab != null)
        {
            Instantiate(deathParticlePrefab, transform.position, Quaternion.identity);
        }

        //DESTRUCTION HANDLER
        if (destroyOnHit)
        {
            canDamage = false;
            Destroy(gameObject);
        }
    }
コード例 #4
0
    protected virtual void MeleeAttack(Component other)
    {
        Base_Health otherHealth = other.GetComponent <Base_Health> ();

        if (otherHealth == null)
        {
            return;
        }
        if (playerTag.Team != 0 && otherHealth.GetPlayerTag().Team == playerTag.Team)
        {
            return;
        }
        float multipliedDamage = damage;

        if (other.GetComponent <OLD_BaseMob> () != null)
        {
            multipliedDamage *= onMobMultiplier;
        }
        else if (other.GetComponent <Player_Health> () != null)
        {
            multipliedDamage *= onPlayerMultiplier;
        }

        if (otherHealth.GetPlayerTag().Id != playerTag.Id)
        {
            otherHealth.TakeDamage(multipliedDamage, playerTag.Id, playerTag.Team);
        }
        StartCoroutine(HitRoutine());
    }
コード例 #5
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (released)
     {
         Base_Health health = other.GetComponent <Base_Health> ();
         if (health != null)
         {
             if (health.GetPlayerTag().Id != playerTag.Id || (health.GetPlayerTag().Team != 0 && health.GetPlayerTag().Team != playerTag.Team))
             {
                 GameObject temp = Instantiate(splashDamagePrefab, transform.position, Quaternion.identity) as GameObject;
                 temp.GetComponent <Base_Bullet> ().SetInfo(playerTag.Id, playerTag.Team);
                 Destroy(gameObject);
             }
         }
     }
     else
     {
         Base_Bullet bullet = other.GetComponent <Base_Bullet> ();
         if (other.GetComponent <Bullet_Explosion> () != null)
         {
             return;
         }
         if (other.GetComponent <Katana_Bullet> () != null)
         {
             return;
         }
         if (bullet != null)
         {
             if (bullet.Id != playerTag.Id && (bullet.Team == 0 || bullet.Team != playerTag.Team))
             {
                 Destroy(other.gameObject);
             }
         }
         else if (other.GetComponent <Base_Mob> () != null)
         {
             if (!canAttack)
             {
                 return;
             }
             Base_Health health = other.GetComponent <Base_Health> ();
             if (health != null)
             {
                 if (health.GetPlayerTag().Id != playerTag.Id && (health.GetPlayerTag().Team == 0 || health.GetPlayerTag().Team != playerTag.Team))
                 {
                     StartCoroutine(AttackCooldown());
                     health.TakeDamage(damage, playerTag.Id, playerTag.Team);
                 }
             }
         }
     }
 }