示例#1
0
        /// <summary>
        /// Applies specified damage to the player.
        /// Applies knockback effect to the player.
        /// </summary>
        /// <param name="spec">
        /// Attack spec applied to the player.
        /// </param>
        /// <param name="collisionPoint">
        /// Vector2 of position where another player collided with the target.
        /// Can be default if damage wasn't applied by a player.
        /// </param>
        private void KnockBody(Attack spec, Vector2 direction, Vector2 collisionPoint)
        {
            StartCoroutine(myAttack.Stun(stunTime));
            StartCoroutine(myMovement.Stun(stunTime));

            // Construct force vector
            var position = myTransform.position;

            float forceX = (spec.direction.x == 0f)
                ? 0
                : position.x > collisionPoint.x ? 1 : -1;

            var forceVector = new Vector2(forceX * direction.x, direction.y) * (KnockbackPercentage * myRegularKnockback);

            myRb.AddForce(forceVector, ForceMode2D.Impulse);

            // Spawn splash effect object
            Instantiate(attackSplashPrefab, collisionPoint, Quaternion.identity);

            // Shake Camera
            ApplyHitToCamera();
        }