【发布时间】:2017-10-30 18:20:45
【问题描述】:
我正在使用 IEnumerator 作为可以重置的计时器。我设置了一个航点系统,您可以在其中凝视一个航点 n 秒以传送到它。我使用 IEnumerator 作为一种控制时间的方法,并阻止意外的传送。它工作正常,但如果我凝视任何光线投射项目,它会在某处弄乱逻辑,您必须查看然后重新查看一个航点以重新启动它。这个失败也发生在我的航路点的所有实例上,看一个然后看别处再看另一个将无法传送。我正在使用 GVR build 1.70 中的 GVR Laser Pointer 和 GVR Reticle(1.100 构建失败)。
代码:
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);
}
}
【问题讨论】:
标签: c# unity3d virtual-reality