[Unity] 룰렛, 화살표 돌리기
★ Youtube 헬로소프트님 강의를 듣고 정리한 내용입니다. (링크 첨부)
유니티 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는 안 됨)