Unity/유니티 기본

[07.05] 좀비 서바이벌 1 - 리소스 임포트 & 조이스틱 설치

ljw4104 2021. 7. 5. 12:58

1. 플랫폼 변경 및 해상도 조절

 

2. 리소스 임포트

 

3. 캐릭터 배치

 

4. 조이스틱 추가

1. 캔버스 설정

 

2. 조이스틱 값에 따른 캐릭터 회전

var angles = new Vector3(0, Mathf.Atan2(this.joystick.Horizontal, this.joystick.Vertical) * 180 / Mathf.PI, 0);
this.playerGo.transform.eulerAngles = angles;

 

3. 조이스틱 값에 따른 캐릭터 움직임

if (this.joystick.Horizontal != 0 && this.joystick.Vertical != 0)
{
    this.playerGo.transform.Translate(Vector3.forward * 1.0f * Time.deltaTime);
}

 

4. 애니메이션 적용 및 조이스틱 전체코드

void Update()
{
    var angles = new Vector3(0, Mathf.Atan2(this.joystick.Horizontal, this.joystick.Vertical) * 180 / Mathf.PI, 0);
    this.playerGo.transform.eulerAngles = angles;

    if (this.joystick.Horizontal != 0 && this.joystick.Vertical != 0)
    {
        this.playerGo.transform.Translate(Vector3.forward * 1.0f * Time.deltaTime);
        this.playerAnimator.SetFloat("Move", 1.0f);
    }
    else
    {
        this.playerAnimator.SetFloat("Move", 0);
    }
}