시점을 변경하고 자동차에 콜라이더를 넣어서
점의 레이캐스트가 닿을 시 인지할 수 있도록 하였다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem.LowLevel;
public class Car : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IGvrPointerHoverHandler
{
private Coroutine coroutine;
public void OnGvrPointerHover(PointerEventData eventData)
{
//Debug.Log("Hover");
}
public void OnPointerEnter(PointerEventData eventData)
{
coroutine = StartCoroutine(CoClick());
Debug.Log("Enter");
}
private IEnumerator CoClick()
{
float delta = 0f;
while (true)
{
delta += Time.deltaTime;
if(delta >= 3)
{
Debug.LogFormat("Clicked , {0}", delta);
delta = 0f;
}
yield return null;
}
}
public void OnPointerExit(PointerEventData eventData)
{
Debug.Log("Exit");
StopCoroutine(coroutine);
}
}
플레이어가 지정한 지정한 위치에 도달하면 방향을 전환하여
다음 목적지를 향해 이동하고 그에 맞춰 VR의 시선이 달라진다.
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class Player : MonoBehaviour
{
public Transform[] wayPoints;
private int nextIdx = 0;
private float speed = 2f;
void Start()
{
}
// Update is called once per frame
void Update()
{
MoveWayPoint();
}
public void MoveWayPoint()
{
Vector3 dir = wayPoints[nextIdx].position - this.transform.position;
// 회전 각도
Quaternion rot = Quaternion.LookRotation(dir);
this.transform.Translate(Vector3.forward * speed * Time.deltaTime);
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, rot, Time.deltaTime * speed);
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("WayPoint"))
{
nextIdx++;
if(nextIdx == 4)
{
nextIdx = 0;
}
}
}
}
'산대특 > VRAR' 카테고리의 다른 글
Oculus Settings and Grab (0) | 2024.04.17 |
---|---|
Reticle (0) | 2024.04.16 |
VR로 360도 동영상 다운로드 후 적용하기 + 오큘러스 적용 (0) | 2024.04.16 |
VR Setting 문제 (0) | 2024.04.12 |
VR Setting 문제 (0) | 2024.04.12 |