IEnumerator Loop()
    {
        while (gameObject.activeInHierarchy)
        {
            isTouch = toggle.isOn;
            if (PaddleChanger.Instance.paddleMode != lastedPaddle)
            {
                PaddleChanger.OnChangePaddle(PaddleChanger.Instance.paddleMode);

                lastedPaddle = PaddleChanger.Instance.paddleMode;
            }

            switch (PaddleChanger.Instance.paddleMode)
            {
            case PaddleMode.Limited:
                if (isTouch)
                {
                    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    transform.position = new Vector2(mousePos.x, -3.3f);
                }
                else
                {
                    dirVelocity          = Vector3.right * Input.GetAxisRaw("Horizontal") * m_fSpeed;
                    rigidbody2D.velocity = dirVelocity;
                }
                break;

            case PaddleMode.Freedom:
                if (isTouch)
                {
                    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    transform.position = new Vector2(mousePos.x, mousePos.y);
                }
                else
                {
                    dirVelocity          = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")) * m_fSpeed;
                    rigidbody2D.velocity = dirVelocity;
                    transform.position   =
                        new Vector2(
                            Mathf.Clamp(transform.position.x, -2.5f, 2.5f)
                            , Mathf.Clamp(transform.position.y, -5f, 5f));
                }
                break;

            default:
                break;
            }
            yield return(null);
        }
        yield return(null);
    }
示例#2
0
    public void ChangePaddle(PaddleMode paddleMode)
    {
        switch (paddleMode)
        {
        case PaddleMode.Limited:
            m_limitedPaddle?.gameObject?.SetActive(true);
            m_freedomPaddle?.gameObject?.SetActive(false);
            break;

        case PaddleMode.Freedom:
            m_freedomPaddle?.gameObject?.SetActive(true);
            m_limitedPaddle?.gameObject?.SetActive(false);
            break;

        default:
            break;
        }
    }
示例#3
0
 public void TEST_CHANGED_FREEDOM_PADDLE()
 {
     //ChangePaddle(PaddleMode.Freedom);
     paddleMode = PaddleMode.Freedom;
 }
示例#4
0
 public void TEST_CHANGED_LIMITED_PADDLE()
 {
     //ChangePaddle(PaddleMode.Limited);
     paddleMode = PaddleMode.Limited;
 }
示例#5
0
 public void SetPaddle(PaddleMode _paddleMode) => paddleMode = _paddleMode;
示例#6
0
 private void OnEnable()
 {
     paddleMode = PaddleMode.Limited;
     ChangePaddle(paddleMode);
 }