Ejemplo n.º 1
0
    private void Move(Vector2 step)
    {
        if (step == Vector2.zero)
        {
            return;
        }

        Vector2 dir      = step.normalized;
        float   distance = step.magnitude;

        if (!hitWall)
        {
            if (Physics2D.Raycast(transform.position, dir, distance, LayerMask.Walls).collider != null)
            {
                hitWall            = true;
                PendingForDeletion = true;
            }
        }

        if (hitWall || lifeTimer >= LifeTime)
        {
            transform.position += (Vector3)step;
            return;
        }

        int count = Physics2D.CircleCastNonAlloc(transform.position, currentRadius, dir, hits, distance, LayerMask.WalkersAndShootables);

        for (int i = 0; i < count; i++)
        {
            RaycastHit2D hit = hits[i];

            Damageable dmg = hit.collider.GetComponentInParent <Damageable>();
            if (owner != null && dmg != null)
            {
                if (owner.gameObject == hit.collider.gameObject)
                {
                    continue;
                }

                if (owner.Faction != Factions.AgainstAll)
                {
                    if (owner.Faction == dmg.Faction)
                    {
                        continue;
                    }
                }
            }

            if (dmg != null)
            {
                if (!alreadyHit.Contains(dmg))
                {
                    alreadyHit.Add(dmg);

                    dmg.Damage(new DamageFrame(Damage, AttackType.Bullet, damageType, owner, hit.point));
                    dmg.Dot(new DotFrame(BurnTotalDamage, DamagePerBurn, damageType, owner));
                    dmg.Impulse(dir, Force);

                    if (HitSound != null)
                    {
                        Sounds.Create3DSound(hit.point, HitSound.clips[0], Sounds.MixerGroup.Effects, HitSound.volume, HitSound.minPitch, HitSound.maxPitch, HitSound.priority, HitSound.minDistance);
                    }
                }
            }
        }

        transform.position += (Vector3)step;
    }