IEnumerator를 사용하여 재설정 할 수있는 타이머로 작동합니다. 나는 웨이 포인트 시스템을 가지고있다. 당신이 n 초 동안 웨이 포인트를보고 응시 한 곳으로 텔레포트한다. IEnumerator를 사용하여 시간을 제어하고 우발적 인 순간 이동을 막을 수 있습니다. 괜찮 으면 좋겠지 만, 어떤 레이캐스팅 항목을 보면 로직 어딘가에 덤비다. 그러면 웨이 포인트를 다시 보면서 모든 것을 다시 시작해야한다. 이 실패는 내 웨이 포인트의 모든 인스턴스에서도 실행됩니다. 하나를보고 멀리 보아 다른 곳을보고 순간 이동하지 못합니다. 나는 GVR 레이저 포인터와 GVR 레티클을 1.70 (1.100 빌드 실패)에서 구축하고 있습니다.IEnumerator로 Unity GVR 시선 이벤트
코드 :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gaze_Waypoints : MonoBehaviour {
public int gazeTime = 3; //the amount of time needed to look to teleport
public GameObject playerCam; //the players camera
private Vector3 waypointPosition; //the position of the current waypoint
private Vector3 playerCamPosition; //the current position of the players camera used for height information
private IEnumerator waypointEnumerator; //my co-routine
private bool startCoRoutine; //is the co-routine running
void Start() {
waypointPosition = transform.position; //get the position of the owners waypoint
waypointEnumerator = waypointTimerEvent(); //set the ienumerator to the relevant function below
startCoRoutine = true; //testing this out as true or false
}
void Update() {
playerCamPosition = playerCam.transform.position; //keep track of the players camera, mainly for height info
}
// when I gaze a waypoint
public void PointerEnter() {
Debug.Log("I entered.");
if (startCoRoutine) {
StartCoroutine (waypointEnumerator);
} else {
StopCoroutine (waypointEnumerator);
}
startCoRoutine = !startCoRoutine;
}
// when I look away
public void PointerExit() {
Debug.Log("I exited.");
StopCoroutine (waypointEnumerator);
}
// if I look for 3 seconds teleport the user, if I look away reset the timer
IEnumerator waypointTimerEvent() {
yield return new WaitForSeconds (gazeTime);
playerCam.transform.position = new Vector3 (waypointPosition.x, waypointPosition.y + playerCamPosition.y, waypointPosition.z);
StartCoroutine(waypointEnumerator);
}
}