我已经使用 Unity 2019 完成了 VR Cardboards 游戏,但问题是我忘记使用 Input.GetKeyDown("Fire1") 声明控制器的每个点击操作。我被分配了所有带有事件触发指针点击的点击事件。所以我无法用控制器玩这个游戏。
我自己结案了。 使用此脚本并通过指针单击将其放入可交互对象。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class PointerTrigger : MonoBehaviour, IPointerEnterHandler,IPointerExitHandler
{
bool active = false;
public void OnPointerEnter(PointerEventData eventData)
{
active = true;
}
public void OnPointerExit(PointerEventData eventData)
{
active = false;
}
private void Update()
{
if (active && Input.GetButtonDown("Fire1"))
{
Debug.Log("Fired");
var pointer = new PointerEventData(EventSystem.current);
ExecuteEvents.Execute(gameObject, pointer, ExecuteEvents.pointerClickHandler);
}
}
}
我希望我可以对这个修复程序进行投票,但我不能,因为我的声誉仍然很低。谢谢你这对我帮助很大。