Buttons

Hello,

So I found the button tutorial thread but it isn’t a tutorial unfortunately… The documents on the looking glass site are informative, but I was hoping to get something for scripting beginners. My buttons don’t work, I have resorted to relying on the alpha keys. Do I need to do something special, such as make my own script based off the button manager? All I want are for the buttons to trigger animations essentially.

Currently they use Alpha 1 and 2 to move back and forth through animations/scenes. Can someone help me? I know it is kind of a noob question, so forgive me.

Are you working with Unity?

yes its unity, thanks for the repllyy

Hi! You should be able to include at the top of your script “using LookingGlass” and then, wherever you need to use the Looking Glass buttons, go “if(ButtonManager.GetButtonDown(ButtonType.Square))” or whichever you want to have an event trigger on button presses.

I rapidly put this script together to access the buttons:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using HoloPlay;

namespace HoloPlay.Extras
{
    public class LookingGlassButtons : MonoBehaviour
    {
        public UnityEvent ButtonSquarePressed;
        public UnityEvent ButtonSquareUp;
        public UnityEvent ButtonSquareDown;

        public UnityEvent ButtonLeftPressed;
        public UnityEvent ButtonLeftUp;
        public UnityEvent ButtonLeftDown;

        public UnityEvent ButtonRightPressed;
        public UnityEvent ButtonRightUp;
        public UnityEvent ButtonRightDown;

        public UnityEvent ButtonCirclePressed;
        public UnityEvent ButtonCircleUp;
        public UnityEvent ButtonCircleDown;

        void Update()
        {
            //
            // Looking Glass Button: Squere /  1 (simulated by Key: 1)
            //

            if (LookingGlass.ButtonManager.GetButton(LookingGlass.ButtonType.SQUARE) == true)
            {
                //Debug.Log("LookingGlass: Square Pressed");
                ButtonSquarePressed.Invoke();
            }

            if (LookingGlass.ButtonManager.GetButtonUp(LookingGlass.ButtonType.SQUARE) == true)
            {
                Debug.Log("LookingGlass: Square Up");
                ButtonSquareUp.Invoke();
            }


            if (LookingGlass.ButtonManager.GetButtonDown(LookingGlass.ButtonType.SQUARE) == true)
            {
                Debug.Log("LookingGlass: Square Down");
                ButtonSquareDown.Invoke();
            }



            //
            // Looking Glass Button: Left Arrow/  2 (simulated by Key: 2)
            //

            if (LookingGlass.ButtonManager.GetButton(LookingGlass.ButtonType.LEFT) == true)
            {
                //Debug.Log("LookingGlass: LeftArrow Pressed");
                ButtonLeftPressed.Invoke();
            }

            if (LookingGlass.ButtonManager.GetButtonUp(LookingGlass.ButtonType.LEFT) == true)
            {
                Debug.Log("LookingGlass: LeftArrow Up");
                ButtonLeftUp.Invoke();
            }


            if (LookingGlass.ButtonManager.GetButtonDown(LookingGlass.ButtonType.LEFT) == true)
            {
                Debug.Log("LookingGlass: LeftArrow Down");
                ButtonLeftDown.Invoke();
            }



            //
            // Looking Glass Button: Right Arrow /  3 (simulated by Key: 3)
            //

            if (LookingGlass.ButtonManager.GetButton(LookingGlass.ButtonType.RIGHT) == true)
            {
                //Debug.Log("LookingGlass: RightArrow Pressed");
                ButtonRightPressed.Invoke();
            }

            if (LookingGlass.ButtonManager.GetButtonUp(LookingGlass.ButtonType.RIGHT) == true)
            {
                Debug.Log("LookingGlass: RightArrow Up");
                ButtonRightUp.Invoke();
            }


            if (LookingGlass.ButtonManager.GetButtonDown(LookingGlass.ButtonType.RIGHT) == true)
            {
                Debug.Log("LookingGlass: RightArrow Down");
                ButtonRightDown.Invoke();
            }



            //
            // Looking Glass Button: Circle /  4 (simulated by Key: 4)
            //

            if (LookingGlass.ButtonManager.GetButton(LookingGlass.ButtonType.CIRCLE) == true)
            {
                //Debug.Log("LookingGlass: Circle Pressed");
                ButtonCirclePressed.Invoke();
            }

            if (LookingGlass.ButtonManager.GetButtonUp(LookingGlass.ButtonType.CIRCLE) == true)
            {
                Debug.Log("LookingGlass: Circle Up");
                ButtonCircleUp.Invoke();
            }


            if (LookingGlass.ButtonManager.GetButtonDown(LookingGlass.ButtonType.CIRCLE) == true)
            {
                Debug.Log("LookingGlass: Circle Down");
                ButtonCircleDown.Invoke();
            }

        }
    }
}

You can put that script on some object (for example a nullobject somewhere in the scene) and you get for each button some events where you could link in your own scripts. I hope this helps to get started.

you are both amazing! and thank you for doing all that for me. It means a lot. I will utilize this.

1 Like