Пример #1
0
        public void ReactToHit(Collision2D collision, int baseDamage, float partDamageMultiplier)
        {
            string collisionName = collision.otherCollider.gameObject.name;

            if (!collisionName.Equals(bulletPrefab.name))
            {
                if (!isInvincible)
                {
                    actorBehavior.Health -= baseDamage;
                }

                // Warn player if health is less than 10%
                if (actorBehavior.Health > 0 && ((float)actorBehavior.Health / actorBehavior.MaxHealth) < 0.3f)
                {
                    Warning("Low Health");
                }

                // todo: Once we have enemies, we should add a weight value to them which will affect the hard coded values below

                // Hit from the left side
                if (collision.otherCollider.transform.position.x < transform.position.x)
                {
                    externalVelocity = externalVelocity.Copy(x: externalVelocity.x + 1f);
                    cameraEffector.Trigger_Impact_Left();
                }
                // Hit from the right side
                else
                {
                    externalVelocity = externalVelocity.Copy(x: externalVelocity.x - 1f);
                    cameraEffector.Trigger_Impact_Right();
                }

                // Hit from the ass
                if (collision.otherCollider.transform.position.y < transform.position.y)
                {
                    externalVelocity = externalVelocity.Copy(y: externalVelocity.x + 1f);
                }
                // Hit from the right side
                else
                {
                    externalVelocity = externalVelocity.Copy(y: externalVelocity.y - 1f);
                }
            }
        }