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

问题描述 投票:0回答:2

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

Example of Event Trigger Pointer Click 有什么办法让我摆脱困境吗?

unity-game-engine game-engine virtual-reality google-vr 360-virtual-reality
2个回答
0
投票

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

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

}

0
投票

我希望我可以对这个修复程序进行投票,但我不能,因为我的声誉仍然很低。谢谢你这对我帮助很大。

© www.soinside.com 2019 - 2024. All rights reserved.