Gamepad movement

2023. 8. 15. 22:27개인적인 공부/Unity

문득 PC 가 아닌 모바일에서 작동환경을 만들면 어떨까 싶어서 따로 공부를 해보았다..

 

 

대략적인 코드는 비슷하고 방향고정만 바뀌었다.

 

기존코드

private void AdjustPlayerFacingDirection(){
        Vector3 mousePos = Input.mousePosition;
        Vector3 playerScreenPoint = Camera.main.WorldToScreenPoint(transform.position);

        if(mousePos.x < playerScreenPoint.x){
            mySpriteRenderer.flipX = true;
            facingLeft = true;
        }else{
            mySpriteRenderer.flipX = false;
            facingLeft = false;
        }
    }​

 

PC 로 구동되는 것이고 마우스가 향하는 곳으로 Player 방향이 향하도록 했다

 

나의 작성코드

private void AdjustPlayerFacingDirection()
    {
        Vector2 movePos = movement;

        if(movePos.x < 0)
        {
            spriteRenderer.flipX = true;
            facingLeft = true;
        }
        else if(movePos.x > 0)
        {
            spriteRenderer.flipX = false;
            facingLeft = false;
        }
    }

Vector3 를 제외하고 

입력 방향으로 Player가 좌우 향하는 쪽으로 만들었다.

 

계속 보완을 해야겠다.

'개인적인 공부 > Unity' 카테고리의 다른 글

Remote Play 확인  (0) 2023.08.22
GamePad Attack  (0) 2023.08.16
2D RPG Top down  (0) 2023.08.11
AudioPlayer  (0) 2023.06.12
Shooting Animation  (0) 2023.05.22