Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Wrist Menu for the Meta Quest 2

Discussion in 'VR' started by stutikafle, Dec 1, 2023.

  1. stutikafle

    stutikafle

    Joined:
    Sep 11, 2023
    Posts:
    7
    Hello everyone.

    I am trying to build wrist menu that could be enabled and disabled using the menu button of the controller. I am unable to do so. Any suggestion is appreciated. Thank you.
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,879
    Which part are you getting stuck on?
     
  3. stutikafle

    stutikafle

    Joined:
    Sep 11, 2023
    Posts:
    7
    I am not able to use the button of the controllers. I tried following one tutorial and did little modification to fit my game. The button does not seem to be working for me. The Ondestroy part works only when I stop the game.

    this is the script

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;

    public class Wrist : MonoBehaviour
    {
    public InputActionAsset inputActions;

    private Canvas _wristUICanvas;
    private InputAction _menu;
    // Start is called before the first frame update
    private void Start()
    {
    Debug.Log("Script Started");

    _wristUICanvas = GetComponent<Canvas>();
    _menu = inputActions.FindActionMap("XRI LeftHand Interaction").FindAction("Menu");
    _menu.Enable();
    Debug.Log("menu found");
    _menu.performed += ToggleMenu;
    Debug.Log("menu updated");
    }

    private void OnDestroy()
    {
    if (_menu != null)
    {
    Debug.Log("Script Stopped");
    _menu.performed -= ToggleMenu;
    }


    }

    public void ToggleMenu(InputAction.CallbackContext context)
    {
    Debug.Log("Toggle menu called");
    _wristUICanvas.enabled = !_wristUICanvas.enabled;
    }
    }
     
  4. baggyg

    baggyg

    Joined:
    Nov 21, 2013
    Posts:
    27
    Because that's when its being destroyed. In your script you are simply deactivating it.

    The two aren't the same. Generally you just want to disable it, not destroy it.