示例#1
0
    public override bool Perform()
    {
        // Someone else killed the enemy
        if (m_TargetEnemy == null || m_TargetEnemy.IsDead)
        {
            m_Killed = true;
            m_Animator.StopThrust();
            return(true);
        }

        if (m_StartTime == 0f)
        {
            m_Animator.PlayThrust();
            m_StartTime = Time.time;
        }

        if (Time.time - m_StartTime > hitTime)
        {
            m_TargetEnemy.DoDamage();

            if (m_TargetEnemy == null || m_TargetEnemy.IsDead)
            {
                m_Animator.StopThrust();
                m_Killed = true;
            }

            m_StartTime = 0f;
        }

        return(true);
    }
示例#2
0
 public static void DoAOEDamage(Vector2 position, float radius, int damage, Faction faction, float knockbackStrength)
 {
     Collider2D[] objectsInRange = Physics2D.OverlapCircleAll(position, radius);
     foreach (Collider2D col in objectsInRange)
     {
         EnemyHealth enemy = col.GetComponent <EnemyHealth>();
         if (enemy != null && enemy.health > 0)
         {
             // linear falloff of effect
             float      proximity = (position - V3toV2(enemy.transform.position)).magnitude;
             float      effect    = Mathf.Clamp01(1 - (proximity / radius));
             DamageInfo info      = new DamageInfo(faction, (int)(damage * effect));
             enemy.DoDamage(info);
             EnemyMovement move = col.GetComponent <EnemyMovement>();
             if (move != null)
             {
                 move.DoKnockback((V3toV2(col.transform.position) - position).normalized * knockbackStrength * effect);
             }
         }
     }
 }
示例#3
0
    public void ProcessHit(int damage, float radius, int health)
    {
        if (radius == 0)
        {
            DoDamage(damage, health);
        }
        else
        {
            Collider[] cols = Physics.OverlapSphere(transform.position, radius);

            foreach (Collider c in cols)
            {
                if (c.GetComponent <EnemyHealth>())
                {
                    enemyHealth = c.GetComponent <EnemyHealth>();
                    enemyHealth.DoDamage(damage);
                    if (enemyHealth.healthPoints <= 0)
                    {
                        enemyHealth.KillEnemy();
                    }
                }
            }
        }
    }