예제 #1
0
파일: PlayerMove.cs 프로젝트: hdmmY/JI-Game
    private void Update()
    {
        float hInput = InputManager.Instance.InputCtrl.HorizontalInput;
        float vInput = InputManager.Instance.InputCtrl.VerticalInput;

        float hSpeed = _player.GetHMoveSpeed();
        float vSpeed = _player.GetVMoveSpeed();

        float horizontalMove = hInput * hSpeed;
        float VerticalMove   = vInput * vSpeed;

        Vector2 playerPos = (Vector2)transform.position +
                            new Vector2(horizontalMove, VerticalMove) * Time.deltaTime;

        // player position is out of bound
        if (playerPos.x < m_moveAreaCentre.x - m_moveAreaShape.x / 2)
        {
            playerPos.x = m_moveAreaCentre.x - m_moveAreaShape.x / 2;
        }
        if (playerPos.x > m_moveAreaCentre.x + m_moveAreaShape.x / 2)
        {
            playerPos.x = m_moveAreaCentre.x + m_moveAreaShape.x / 2;
        }
        if (playerPos.y < m_moveAreaCentre.y - m_moveAreaShape.y / 2)
        {
            playerPos.y = m_moveAreaCentre.y - m_moveAreaShape.y / 2;
        }
        if (playerPos.y > m_moveAreaCentre.y + m_moveAreaShape.y / 2)
        {
            playerPos.y = m_moveAreaCentre.y + m_moveAreaShape.y / 2;
        }

        transform.position = new Vector3(playerPos.x, playerPos.y, transform.position.z);
    }