如何在 Google VR Cardboard Unity 2019 中将事件触发指针单击指定为 Fire1

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

Example of Event Trigger Pointer Click 有什么办法可以让我摆脱这种情况吗?

lite840 回答:如何在 Google VR Cardboard Unity 2019 中将事件触发指针单击指定为 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);
        }
    }

}
本文链接:https://www.f2er.com/287433.html

大家都在问