Exemplo n.º 1
0
        void DoExplosionDamage(Vector3 center, float radius)
        {
            var hitColliders = Physics2D.OverlapCircleAll(center, radius);
            var thisCollider = GetComponent <Collider2D>();

            foreach (var hitCollider in hitColliders)
            {
                if (hitCollider == thisCollider)
                {
                    continue;
                }

                var barrierScript = hitCollider.GetComponent <BarrierScript>();
                if (barrierScript != null)
                {
                    var dist = hitCollider.Distance(thisCollider);

                    // je weiter die barriere weg ist, desto weniger schaden nimmt sie
                    var f = 1 - Mathf.Clamp(dist.distance, 0, TotalRadius) / TotalRadius;

                    // je stärker die übertragene kraft ist um so mehr schaden bewirkt
                    // die explosion
                    var demage = Math.Max(f * power, BurstMinimumForce);
                    barrierScript.DoDemage(Hit.FromFullLife(demage), false);
                }
            }
        }
Exemplo n.º 2
0
        private void OnLaserCollider2DStay(TriggerScript laser, Collider2D collidedWith)
        {
            BarrierScript b;

            if (Active && (b = collidedWith.GetComponent <BarrierScript>()) != null)
            {
                var hit = barrierHits.FirstOrDefault(h => h.IsBarrier(b));
                if (hit != null)
                {
                    hit.Update();
                    if (hit.Runtime >= Random.Range(RandomIntervalMin, RandomIntervalMax))
                    {
                        if (laserRightHit != null && b.gameObject == laserRightHit.gameObject)
                        {
                            b.DoDemage(Hit.FromFullLife(ForcePerSecond));
                            hit.ResetRuntime();
                        }

                        if (laserLeftHit != null && b.gameObject == laserLeftHit.gameObject)
                        {
                            b.DoDemage(Hit.FromFullLife(ForcePerSecond));
                            hit.ResetRuntime();
                        }
                    }
                }
            }
        }