如何在Google VR Cardboard Unity 2019中将事件触发指针点击分配为Fire1



我已经使用Unity 2019完成了VR Cardboards游戏,但问题是我忘记用Input.GetKeyDown("Fire1"(声明控制器的每个点击动作。我被分配了带有事件触发器Pointer click的所有点击事件。所以我不能用控制器玩这个游戏。

事件触发器指针点击示例有什么办法让我摆脱困境吗?

我自己结案。使用此脚本并通过指针单击将其放置到可交互对象。

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

最新更新