[Unity] 룰렛, 화살표 돌리기

2021. 9. 12. 23:00·Game/Unity

★ Youtube 헬로소프트님 강의를 듣고 정리한 내용입니다. (링크 첨부)

https://youtu.be/UOrrHE7Og68

 

유니티 9강. 회전하는 룰렛 게임 만들기

이 강의는 길벗출판사 유니티 교과서 교재 PPT를 사용하였습니다. https://book.naver.com/bookdb/book_detail.nhn?bid=15655423 입문용 교재로 추천합니다. ----- 유니티 2019.4.6f1 , GoogleVR, VuforiaAR, ARCore 등을 이용

youtu.be


<룰렛>

1. Project Assets 창에 룰렛 판과 바늘을 드래그, 드랍 후, 화면에 위치시키기

 

2. 뒷 배경 설정을 위해 Main Camera > Clear Flags > Solid Color 하고, 색 고르기

 

3. 원판을 돌아가게 하기 위한 C# 스크립트 작성

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Control : MonoBehaviour
{
    float rotationSpeed = 0; 

    void Start()
    {
    
    }

    void Update()
    {
        transform.Rotate(0, 0, rotationSpeed);
        rotationSpeed *= 0.998f; //서서히 멈추게 하기 위함이다

        if(Input.GetMouseButton(0))
        {
            rotationSpeed = 6;
        }
    }
}

 

<화살표 돌리기>

1. 원과 화살 드래그&드랍

 

2. 뒷배경 설정

 

3. C# 스크립트 작성

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Arrowcontrol : MonoBehaviour
{
    float rotationSpeed = 0;
  
    void Start()
    {

    }

    void Update()
    {
        transform.Rotate(0, 0, rotationSpeed);
        rotationSpeed *= 0.998f;

        if (Input.GetMouseButton(0))
        {
            rotationSpeed = Random.Range(360,720) * Time.deltaTime ; 
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();        
        }
    }
}

- Random.Range()는 범위 안에서 랜덤하게 값을 설정한다. 한 값으로 고정 설정을 하면 항상 거의 같은 결과가 나오기 때문에 이렇게 설정했다. (360이면 초당 한 바퀴, 720이면 초당 2바퀴)

- Time.deltaTime은 프레임의 시간이다. 각 기기마다 달라지는 값이다. 

기본적으로 1 / 60 이다. (1초당 60프레임)

 

<Build 하는 방법>

1. file > Build Settings

 

2. Platform 선택 후, Switch Platform

 

3. Player Settings에 들어가서 회사명, 프로젝트 이름, 버전 설정

 

<패키지 export>

Assets > Export Package

--> 한국어로 설정이 가능하다. (apk는 안 됨)

'Game > Unity' 카테고리의 다른 글

[Unity] #1 개발 일지  (0) 2021.09.15
[Unity] 유니티 미들웨어  (0) 2021.09.14
[Unity] C# 스크립트 기초  (0) 2021.09.12
[Unity] Failed to create GICache directory at the default location 에러 해결 방법  (0) 2021.09.08
[Unity] 단위, 오브젝트  (0) 2021.09.07
'Game/Unity' 카테고리의 다른 글
  • [Unity] #1 개발 일지
  • [Unity] 유니티 미들웨어
  • [Unity] C# 스크립트 기초
  • [Unity] Failed to create GICache directory at the default location 에러 해결 방법
Rix
Rix
  • Rix
    The Nights
    Rix
  • 전체
    오늘
    어제
  • 글쓰기 관리
    • 분류 전체보기 (106)
      • 알고리즘 (5)
        • Python (1)
        • C++ (6)
      • CS (0)
      • Backend (20)
        • 로드맵 (1)
        • Java (17)
        • Spring (2)
      • TIL (0)
      • Flutter (13)
      • Python (7)
        • 디스코드 챗봇 (1)
        • 문법 (1)
        • 머신러닝 (2)
      • C (28)
        • 문법 (19)
      • ETC (2)
        • Git (2)
        • GitHub (1)
        • Hacking (4)
      • Game (13)
        • Unity (13)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    2차원 배열
    1152
    C
    c언어
    절대강좌유니티
    미로찾기
    문자열 함수
    콘솔창
    TensorFlow
    코뮤니티
    Failed to create GICache
    Unity
    이중포인터
    공백포함
    백준
    DART
    nullsafety
    이미지분류
    1546
    C심화
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
Rix
[Unity] 룰렛, 화살표 돌리기
상단으로

티스토리툴바