강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của parkhyungjoo0619
parkhyungjoo0619

câu hỏi đã được viết

Tinh chất lập trình trò chơi Unity C# trong Retro

nòng xoay

동작이 안됩니다.

Viết

·

270

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");
                }
            }
        }
    }
}
C#unity

Câu trả lời 2

0

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

저 부분이 잘못됐네요 ㅎㅎ

state == Rotate.Vertical

조건문 체크가 

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

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

0

parkhyungjoo0619님의 프로필 이미지
parkhyungjoo0619
Người đặt câu hỏi

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

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

자문자답. 끝. 

Hình ảnh hồ sơ của parkhyungjoo0619
parkhyungjoo0619

câu hỏi đã được viết

Đặt câu hỏi