Exemple #1
0
    public void FixedUpdate()
    {
        if (explodeNextFrame)
        {
            Collider2D[] colliders = Physics2D.OverlapCircleAll(this.transform.position, this.damageRadius);

            foreach (Collider2D collider in colliders)
            {
                Damagable damagable = collider.GetComponent <Damagable>();

                if (damagable == null)
                {
                    continue;
                }

                Vector2 damagePoint             = collider.ClosestPoint(this.transform.position);
                float   distance                = Vector2.Distance(this.transform.position, damagePoint);
                float   distanceDamageReduction = this.damage * (distance / damageRadius);
                damagable.ApplyDamage(this.damage - distanceDamageReduction);
            }

            ProjectileManager.Projectiles.Remove(this.id);
            Destroy(this.gameObject);
        }
    }
Exemple #2
0
    public static void MakeMeeleAttack(float damage, float radius, Vector3 center, Damagable self, float force = 0, string ignoreTag = "")
    {
        var colliders = Physics.OverlapSphere(center, radius);
        List <Damagable> targetDam = new List <Damagable>();

        foreach (Collider collider in colliders)
        {
            Damagable dam = null;
            if ((dam = collider.gameObject.GetComponentInParent <Damagable>()) && dam != self && !targetDam.Contains(dam) && collider.gameObject.tag != ignoreTag)
            {
                dam.ApplyDamage(damage);
                targetDam.Add(dam);
            }
        }

        colliders = Physics.OverlapSphere(center, radius);
        List <Rigidbody> targetRB = new List <Rigidbody>();
        Rigidbody        selfBody = self.gameObject.GetComponent <Rigidbody>();

        Vector3 forceVec = (center - self.gameObject.transform.position).normalized * force;

        foreach (Collider collider in colliders)
        {
            Rigidbody rb = null;
            if ((rb = collider.gameObject.GetComponentInChildren <Rigidbody>()) && rb != selfBody && !targetRB.Contains(rb) && collider.gameObject.tag != ignoreTag)
            {
                rb.AddForce(forceVec);
                targetRB.Add(rb);
            }
        }
    }
Exemple #3
0
    public void ApplyDamage(float damage, Collision col = null)
    {
        damage = Mathf.Round(damage);

        if (healthPool != null)
        {
            Rigidbody b;
            if (b = healthPool.gameObject.GetComponent <Rigidbody>())
            {
                healthPool.ApplyDamage(damage * rb.mass / b.mass);
            }
            else
            {
                healthPool.ApplyDamage(damage);
            }
        }
        else if (health > 0)
        {
            damage -= damageThreshhold;


            if (damage <= 0)
            {
                return;
            }

            health -= damage;

            if (gameObject.GetComponent <EnemyBehaviorScript>())
            {
                DamageTextController.CreateDamageText(damage.ToString(), transform);
            }

            gameObject.SendMessage("TakeDamage", SendMessageOptions.DontRequireReceiver);
            if (health <= 0)
            {
                if (col != null)
                {
                    gameObject.SendMessage("DieCollision", col, SendMessageOptions.DontRequireReceiver);
                }

                SendMessage("Die", SendMessageOptions.DontRequireReceiver);
            }
        }
    }
Exemple #4
0
    void Explode()
    {
        Debug.Log("boom!");

        Collider[] colliders = Physics.OverlapSphere(transform.position, radius);

        List <Rigidbody> explosionList = new List <Rigidbody>();
        List <Damagable> damagableList = new List <Damagable>();

        foreach (Collider collider in colliders)
        {
            GameObject go = collider.gameObject;

            Rigidbody rb = null;

            while (go.transform.parent != null && !go.GetComponent <Damagable>())
            {
                if (go.layer != go.transform.parent.gameObject.layer)
                {
                    break;
                }

                go = go.transform.parent.gameObject;
                rb = go.GetComponentInChildren <Rigidbody>();
            }

            Debug.Log(go.name);

            if (!explosionList.Contains(rb) && rb != null)
            {
                rb.AddExplosionForce(power, transform.position, radius, 0.3f);
                explosionList.Add(rb);
            }

            Damagable d = go.GetComponent <Damagable>();
            //if(d==null)
            //d = go.GetComponentInChildren<Damagable>();

            if (d != null && !damagableList.Contains(d))
            {
                float damageAmount = 1 - (Vector3.Distance(transform.position, collider.ClosestPointOnBounds(transform.position)) / radius);

                damageAmount *= damage;

                d.ApplyDamage(damageAmount);

                damagableList.Add(d);
            }
        }

        Instantiate(explosionEffect, transform.position, Quaternion.identity);
    }
    private void Update()
    {
        GameObject go = AIUtilities.GetNearestGameObject(gameObject, attack.Target, 0, attack.Nc.Fov, attack.Nc.SeeThroughWalls);

        if (go != null && !hit)
        {
            hit = true;
            Damagable health = go.GetComponent <Damagable>();
            if (health != null)
            {
                health.ApplyDamage(Damage);
            }
            if (DestroyOnHit)
            {
                Destroy(gameObject);
            }
        }
    }