Unity AR Virtual Button to Control Scenes

Hi everyone. I am new to Unity and I really appreciate you guys if you could help. I would like to drag and drop scenes into a next scene selection similar to public Gameobject xxx;

Because I have multiple scenes to work with so creating a new script for a new scene is not efficient. Thanks in advance.

using UnityEngine;
using UnityEngine.SceneManagement;
using Vuforia;

public class Vb_changescene : MonoBehaviour, IVirtualButtonEventHandler {

public GameObject VirtualButton;
public GameObject Scenename;

// Use this for initialization
void Start()
{
VirtualButton = GameObject.Find(“Next”);
VirtualButton.GetComponent()
.RegisterEventHandler(this);
}
public void OnButtonPressed(VirtualButtonBehaviour vb)
{
Debug.Log(“Btn Pressed”);
SceneManager.LoadScene(Scenename);
}

public void OnButtonReleased(VirtualButtonBehaviour vb)
{
Debug.Log(“Btn Released”);
}
}

Hello Frederic,

I’m not an expert but I’m working on the same option as you.
The “IVirtualButtonEventHandler” is deprecated actually so you don’t need it anymore.

And you have to modify in void Start()
VirtualButton.GetComponent()
.RegisterEventHandler(this);

by

VirtualButton.GetComponent().RegisterOnButtonPressed(OnButtonPressed);
VirtualButton.GetComponent().RegisterOnButtonReleased(OnButtonReleased);

Hope it’ll help you and work fine :wink:

See you

Jason

hi
I also made a project just like you guys, I’m a unity beginner. I want to ask if all that code is working in a new gameobject or in a VirtualButtonEventHandler? I’m confused how to call another scene using virtual button. pls help me. thank you