
강의해주신 내용과 같이 코딩을 했는데, 마우스 버튼을 눌렀다가 떼었을 때 세로 방향으로 돌지 않습니다.
단계별로 state가 넘어가는지 확인하기 위해 디버그.로그 코드를 넣어 놓았습니다.
제가 무엇을 잘못해서 동작하지 않는 것일까요? 답변 부탁드립니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShooterRotator : MonoBehaviour
{
private enum RotateState
{
Idle,Vertical,Horizontal,Ready
}
private RotateState state = RotateState.Idle;
public float verticalRoteteSpeed = 360f;
public float horizontalRoteteSpeed = 360f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(state == RotateState.Idle)
{
if(Input.GetButtonDown("Fire1"))
{
state = RotateState.Horizontal;
}
}
else if(state == RotateState.Horizontal)
{
if(Input.GetButton("Fire1"))
{
transform.Rotate(new Vector3(0,horizontalRoteteSpeed * Time.deltaTime,0));
}
else if(Input.GetButtonUp("Fire1"))
{
state = RotateState.Vertical;
Debug.Log("1");
}
else if(state == RotateState.Vertical)
{
if(Input.GetButton("Fire1"))
{
transform.Rotate(new Vector3(-verticalRoteteSpeed * Time.deltaTime,0,0));
Debug.Log("2");
}
else if(Input.GetButtonUp("Fire1"))
{
state = RotateState.Ready;
Debug.Log("3");
}
}
}
}
}
안되서 계속 진도 나가니 switch case 문법을 알려주시네요.
이걸 사용하니 동작하네요.
자문자답. 끝.