• 카테고리

    질문 & 답변
  • 세부 분야

    게임 프로그래밍

  • 해결 여부

    미해결

동작이 안됩니다.

20.01.03 20:04 작성 조회수 116

0

강의해주신 내용과 같이 코딩을 했는데, 마우스 버튼을 눌렀다가 떼었을 때 세로 방향으로 돌지 않습니다. 

단계별로 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");
                }
            }
        }
    }
}

답변 2

·

답변을 작성해보세요.

0

hwakyeom님의 프로필

hwakyeom

2020.03.06

            }
            else if(state == RotateState.Vertical)
            {

저 부분이 잘못됐네요 ㅎㅎ

state == Rotate.Vertical

조건문 체크가 

        if(state == RotateState.Idle)
        {
               ..{
               }
        }
        else if(state == RotateState.Horizontal)
        {
              ..{
               }
               else if(state == RotateState.Vertical)
              {
              }
        }

저렇게 Horizontal 조건문 내부에 들어가 있어요 ㅋㅋ

0

박형주님의 프로필

박형주

질문자

2020.01.04

안되서 계속 진도 나가니 switch case 문법을 알려주시네요.

이걸 사용하니 동작하네요. 

자문자답. 끝.