VR을 활용한 방탈출 프로젝트 개발내용을 정리한 내용입니다.
Interaction Toolkit 의 버전은 2.4.3
버전을 사용했습니다.
이번 VR 방탈출의 요구사항
은 다음과 같았다
요구사항 : VR로 움직일 수 있는 1인칭 플레이어 구현
아이디어 : Locomotion
, Continuous Turn Provider
활용
Locomotion
, Continuous Turn Provider
추가요구사항 : 각 맵을 이동하는 텔레포트 기능 구현
아이디어 : Teleportation Provider
를 활용하거나, Collider
와 Transform
이동으로 구현
Teleportation Provider
추가요구사항 : 대화가 아닌 대사만 존재하는 UI를 출력하는 기능을 만들기
아이디어 : XR Simple Interactable
에 있는 Gaze Hover
기능 사용하기
XR Simple Interactable
를 추가Gaze Configuration
항목의 Allow Gaze Interaction
체크Interactable Events
에 First Hover Entered
에 띄울 오브젝트를 넣고 SetActive를 true
, Last Hover Exited
에 같은 오브젝트를 넣고 SetActive를 false
간단하게 키패드 모양을 만들어주고 Keypad
스크립트를 추가했다.
각 Button에는 XRSimpleInteractable
를 추가하고, Select Entered에 Keypad
의 InputCode를 넣어주었다. (파라미터는 각 숫자값)
지우기 버튼에는 EraseCode, OK버튼에는 ConfirmCode를 연결해서 비밀번호 맞춤여부를 확인하도록 작성했다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Keypad : MonoBehaviour
{
public TextMeshProUGUI code;
string codeTextDefault = "____";
string codeTextAnswer = "1234";
bool isDone = false;
public List<string> codeList = new List<string>();
public void InputCode(int code)
{
if (isDone) return;
if (codeList.Count >= 4)
{
return;
}
else
{
codeList.Add(code.ToString());
UpdateCode();
}
}
public void UpdateCode()
{
code.text = "";
for (int i = 0; i < codeList.Count; i++)
{
code.text += codeList[i];
}
for (int i = codeList.Count; i < 4; i++)
{
code.text += "_";
}
}
public void ConfirmCode()
{
if (isDone) return;
if (code.text == codeTextAnswer)
{
isDone = true;
// 정답처리 기능
code.text = "PASS";
}
else
{
code.text = codeTextDefault;
codeList = new List<string>();
}
}
public void EraseCode()
{
if (isDone) return;
if (codeList.Count >= 1)
{
codeList.RemoveAt(codeList.Count - 1);
UpdateCode();
}
}
}