我正在尝试在UI上使用Cardboard Gaze脚本。此脚本附加到相机,UI项目正在实施ICardboardResponder
但没有成功。
答案 0 :(得分:0)
试试这个脚本
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
}
}
}