0
我正在使用IEnumerator作为可重置的计时器。我建立了一个航路点系统,你可以在这里注视一个航路点,持续n秒以传送到它。我使用IEnumerator作为控制时间的方法,并且阻止意外的传送。它可以正常工作,但是如果我注视任何光线播放项目,它会在某个地方混淆逻辑,并且必须重新审视一个航点,然后再次启动它。这种失败也会在我的航点的所有实例上出现,看看其中一个,然后看向另一个将无法传送。我正在使用GVR版本1.70(1.100无法构建)的GVR激光笔和GVR分划板。使用IEnumerator的Unity GVR Gaze事件
的代码:
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);
}
}