public void Update()
    {
        m_TransitionState = null;

        HandleSteerAndFalling();

        HandleIfShouldSpearThrow();

        if (m_BGScroller != null)
        {
            m_BGScroller.UpdateFromMoveStep();
        }

        if (m_FallingCamera != null)
        {
            m_FallingCamera.TryToFollow();
        }

        if (m_TransitionState != null)
        {
            m_Player.ChangeToState(m_TransitionState);
        }
    }
Exemplo n.º 2
0
    public void Update()
    {
        HandleFallMovement();

        if (m_BGScroller != null)
        {
            m_BGScroller.UpdateFromMoveStep();
        }

        if (m_FallingCamera != null)
        {
            m_FallingCamera.TryToFollow();
        }

        if (m_ActiveSpearThrow)
        {
            if (m_BackgroundTap.GetHasInput() && m_Player.Spear.CanClamp)
            {
                m_Player.ChangeToState(m_Player.AttachedToObjectState);
            }

            return;
        }

        if (!m_ActiveSpearThrow && m_BackgroundTap.GetHasInputUp())
        {
            float timeInState = Time.realtimeSinceStartup - m_StateStartTime;

            if (timeInState > .25f)
            {
                //This means we held long enough in a direction to say: "yeah, player was throwing spear in direction"
                m_ActiveSpearThrow = true;
                m_Player.Spear.Clear();
                m_Player.Spear.FireIntoDirection(m_Player.transform.position,
                                                 m_JumpBoostRightArrow.right,
                                                 () => m_Player.ChangeToState(m_Player.IdleState));

                m_JumpBoostRightArrow.gameObject.SetActive(false);
            }
            else
            {
                m_Player.ChangeToState(m_Player.IdleState);
            }

            return;
        }

        //This means player is still holding down, so we update throw direction here:

        if (!m_JumpBoostRightArrow.gameObject.activeSelf)
        {
            m_JumpBoostRightArrow.gameObject.SetActive(true);
        }

        Vector2 playerScreenPos = Camera.main.WorldToScreenPoint(m_Player.transform.position);
        Vector2 arrowDirPos     = Input.mousePosition;
        Vector2 lookAt          = (arrowDirPos - playerScreenPos).normalized;
        float   jumpBoostAngle  = Mathf.Atan2(lookAt.y, lookAt.x) * Mathf.Rad2Deg;

        m_JumpBoostRightArrow.rotation      = Quaternion.Euler(new Vector3(0f, 0f, jumpBoostAngle));
        m_JumpBoostRightArrow.localPosition = m_JumpBoostRightArrow.transform.right * .3f;

        m_DisplayRoot.localScale = new Vector3(Mathf.Abs(m_DisplayRoot.localScale.x) * (lookAt.x < 0f ? -1f : 1f),
                                               m_DisplayRoot.localScale.y,
                                               m_DisplayRoot.localScale.z);
    }