Exemplo n.º 1
0
    // ====================================================
    private IEnumerator SwapCoroutine(SwappableEntity swappableEntity)
    {
        SoundManager.instance.PlaySound(SoundManager.SoundType.Swap);

        Vector2 previousPos   = transform.position;
        Vector2 previousSpeed = currentSpeed;

        transform.position = VectorUtils.GetPosition3D(swappableEntity.GetPosition());

        bool wasSwappableEntityGrounded = swappableEntity.physicsController.isGrounded;

        swappableEntity.SetPosition(previousPos);
        swappableEntity.SetVelocity(previousSpeed);

        PatrollingEnemy patroller = swappableEntity as PatrollingEnemy;

        if (patroller != null)
        {
            patroller.SetDirectionAsForward();
        }
        swappableEntity.OnSwap();

        isSwapping = true;

        deathVfxAnimator.SetTrigger("deathTrigger");
        animator.gameObject.SetActive(false);
        yield return(new WaitForSeconds(0.2f));

        isSwapping = false;
        animator.gameObject.SetActive(true);
        currentSpeed = previousSpeed;

        Vector2 direction = joystickController.GetDirection();

        if (direction.x > 0.4f)
        {
            currentSpeed.x = maxHorizontalSpeed;
        }
        else if (direction.x < -0.4f)
        {
            currentSpeed.x = -maxHorizontalSpeed;
        }
        else
        {
            currentSpeed.x = 0f;
        }

        if (wasSwappableEntityGrounded)
        {
            currentSpeed.y = 0f;
        }
        else
        {
            currentSpeed.y = currentSpeed.y < 0f ? 0f : currentSpeed.y;
        }
        canDoubleJumped = true;

        prevPos = VectorUtils.GetPosition2D(transform.position);
    }
Exemplo n.º 2
0
 // ====================================================
 public void Swap(SwappableEntity swappableEntity)
 {
     StartCoroutine(SwapCoroutine(swappableEntity));
 }