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);
}
}