Exemplo n.º 1
0
    void MiddleSwitchingDirection()
    {
        if (!started)
        {
            return;
        }
        switchingDirectionState = SwitchingDirectionState.Middle;
        Vector2 reflection     = Vector2.Reflect(ball.transform.position - transform.position, transform.up);
        Vector2 targetPosition = (Vector2)ball.transform.position + reflection;

        RaycastHit2D hitBelow = Physics2D.Raycast(targetPosition, -transform.up, Mathf.Infinity, groundLayer);

        if (hitBelow)
        {
            rb.position  = targetPosition;
            sprite.flipX = !sprite.flipX;
        }
        else
        {
            RaycastHit2D hitAbove = Physics2D.Raycast(targetPosition, transform.up, Mathf.Infinity, groundLayer);
            if (!hitAbove)
            {
                Debug.LogError("Can't teleport - not hitting anywhere!");
            }
            else
            {
                targetPosition = hitAbove.point + hitAbove.normal * (-characterSize / 2);
                rb.position    = targetPosition;
                sprite.flipX   = !sprite.flipX;
            }
        }

        return;
    }
Exemplo n.º 2
0
 void Awake()
 {
     shouldSwitchDirection   = false;
     switchingDirectionState = SwitchingDirectionState.Stop;
     rb           = GetComponent <Rigidbody2D>();
     sprite       = GetComponentInChildren <SpriteRenderer>();
     ac           = GetComponent <Animator>();
     touchingBall = false;
     Hide();
 }
Exemplo n.º 3
0
 void StopSwitchingDirection()
 {
     switchingDirectionState = SwitchingDirectionState.Stop;
 }
Exemplo n.º 4
0
 void StartSwitchingDirection()
 {
     ac.SetTrigger("SwitchBallSide");
     switchingDirectionState = SwitchingDirectionState.Start;
 }