Unity VR Cardboard Gaze不能在UI上工作
问题描述:
我正在尝试在UI上工作Cardboard Gaze脚本。该脚本附加到相机,并且UI项目正在实施ICardboardResponder,但没有成功。Unity VR Cardboard Gaze不能在UI上工作
答
试试这个脚本
void FixedUpdate() {
var pointerEventData = new PointerEventData(EventSystem);
Vector2 hotspot = new Vector2(0.5f, 0.5f);
if(UnityEngine.VR.VRSettings.enabled)
pointerEventData.position = new Vector2(hotspot.x * UnityEngine.VR.VRSettings.eyeTextureWidth, hotspot.y * UnityEngine.VR.VRSettings.eyeTextureHeight);
else
pointerEventData.position = new Vector2(hotspot.x * Screen.width, hotspot.y * Screen.height);
List<RaycastResult> raycastResults = new List<RaycastResult>();
EventSystem.RaycastAll(pointerEventData, raycastResults);
for (var i = 0; i < raycastResults.Count; i++)
{
var hit = raycastResults[i];
var other = hit.gameObject;
var cardboardResponder = other.GetComponent<ICardboardResponder>()
if (cardboardResponder != null)
{
//Do domething
}
}
}