Exemplo n.º 1
0
    IEnumerator Explode()
    {
        yield return(new WaitForSeconds(ImplosionFx.TotalDuration));

        ExplosionFx.Burst(_audio);

        foreach (var item in Physics.OverlapSphere(transform.position, Radius))
        {
            if (_origin && item.gameObject == _origin)
            {
                continue;
            }

            var obj    = item.gameObject;
            var target = obj.GetComponent <Target>();
            if (target)
            {
                obj.transform.LookAt(new Vector3(transform.position.x, obj.transform.position.y, transform.position.z));
                target.KnockDown();
                target.Hit(Damage);
            }

            var rb = obj.GetComponent <Rigidbody>();
            if (rb)
            {
                var dir = (item.transform.position - transform.position).normalized;
                rb.velocity += dir * Force;
            }
        }
    }