Topic has a solution
Log in or register to post comments

How to call a scene in unity using virtual buttons

July 15, 2021 - 8:34am #1
Topic solved

Hi!!!

I want to ask how to call another scene but using virtual button?, I use user defined target method

How to call a scene in unity using virtual buttons

September 6, 2021 - 7:47pm #25

i'll try it, thank you so much for helping me^^

How to call a scene in unity using virtual buttons

August 26, 2021 - 3:29am #24

Hey there,

 

I think we're running in circles here a little. I am not sure anymore if you have a specific question regarding the virtual buttons.

Again I would suggest to validate with debugging if the OnButtonPressed method gets called, and if so, the virtual buttons work.

If the SceneManager.LoadScene method doesn't work, as suggested you should validate that the string you're passing is the same as the name of your scene that you wanted to switch to. If this doesn't work, I sadly will have to point you to the Unity forum, since that would be a Unity issue rather than a Vuforia Engine one.

If you have any other question related to Vuforia Engine, don't hesitate to ask!

 

Kind regards,

Patrick Scheper

Technical Community Manager

How to call a scene in unity using virtual buttons

August 24, 2021 - 7:40am #23

hi!!!

sorry i want to ask if it can use virtual button? because virtual buttons must use OnButtonPressed and OnButtonReleased

How to call a scene in unity using virtual buttons

August 24, 2021 - 5:50am #22

No worries! You should pass the exact scene name in the LoadScene method. When you look at the Unity documentation it looks like:

SceneManager.LoadScene("OtherSceneName", LoadSceneMode.Additive);

So in your case you should change "OtherSceneName" into whatever your next scene is called.

I hope that helps a little...

 

Kind regards,

Patrick Scheper

Technical Community Manager

How to call a scene in unity using virtual buttons

August 23, 2021 - 9:24am #21

I want to make Scenename a string in the public void OnButtonPressed(VirtualButtonBehaviour vb) section but I'm confused it won't work. I'm sorry if I confused you

How to call a scene in unity using virtual buttons

August 23, 2021 - 8:54am #20

Hey there,

 

Shouldn't the Scenename variable be a string? Does that variable get passed into the SceneManager.LoadScene() method? Currently it's a GameObject, so that does not work.

 

Kind regards,

Patrick Scheper

Technical Community Manager

How to call a scene in unity using virtual buttons

August 23, 2021 - 8:43am #19

actually I'm confused at this part I thought at first it could be added another scene because I wanted it like that but it only works for that scene, it can't work to change to another scene

AttachmentSize
Image icon sample.png369.72 KB

How to call a scene in unity using virtual buttons

August 23, 2021 - 2:53am #18

Hey there,

 

You usually get that error when you haven't defined the variable in the inspector. Have you added the VBTN script to your image target and attached the virtual button object to the VirtualButton variable?

 

Kind regards,

Patrick Scheper

Technical Community Manager

How to call a scene in unity using virtual buttons

August 20, 2021 - 1:34pm #17

hi!!

the virtual button appears but can't move to another scene. I don't know the error in the "UnassignedReferenceException: The variable btn_info of VBTN has not been assigned.

You probably need to assign the btn_info variable of the VBTN script in the inspector" because I've adjusted the variable name

AttachmentSize
Image icon ex.png880.6 KB

How to call a scene in unity using virtual buttons

August 20, 2021 - 5:45am #16

When you call Debug.Log(vb.name) on line 22, does that log the name in the console?

 

Kind regards,

Patrick Scheper

Technical Community Manager

How to call a scene in unity using virtual buttons

August 19, 2021 - 4:03pm #15

I've adjusted the name of the scene to be created but still can't move to another scene. I tried changing the code a little bit but it doesn't work either. I want to make a virtual button if pressed it will move to another scene like this photo

AttachmentSize
Image icon kode2.png153.05 KB
Image icon 20210820_055339.jpg7.54 MB

How to call a scene in unity using virtual buttons

August 19, 2021 - 4:42am #14

When you call Debug.Log(vb.name) on line 22, does that get called when the virtual button is pressed? If so, then I don't know why Unity doesn't change scenes. Make sure that the string you are passing ("SceneBrosur") is the same name as the scene you want to change to.

 

Kind regards,

Patrick Scheper

Technical Community Manager

How to call a scene in unity using virtual buttons

August 18, 2021 - 9:15am #13

hi I've successfully updated to 9.8 and no more errors. sorry I want to ask why I can't call another scene, is there something wrong with my code?

AttachmentSize
Image icon kode.png151.38 KB

How to call a scene in unity using virtual buttons

August 18, 2021 - 7:33am #12

Hey there,

 

That's why I said below you should use 9.8, instead of 10.0. The video you followed is on the older version, not the newest!

 

Kind regards,

Patrick Scheper

Technical Community Manager

How to call a scene in unity using virtual buttons

August 17, 2021 - 2:11pm #11

hi!!!

I've updated my vuforia to the latest version but the error is still the same and the error is still the same as before

AttachmentSize
Image icon ERROR2.png70.78 KB

How to call a scene in unity using virtual buttons

August 17, 2021 - 8:03am #10

Hey there,

 

Make sure that you're using 9.8 for that tutorial. Our API changed in 10.0 which is probably why you're receiving errors.

 

Kind regards,

Patrick Scheper

Technical Community Manager

How to call a scene in unity using virtual buttons

August 17, 2021 - 4:32am #9

I've followed the tutorial but I have a problem, what's wrong with my code? can you see the error? thank you

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.SceneManagement;

using Vuforia;

public class VBTN : MonoBehaviour, IVirtualButtonEventHandler {

public GameObject cube;

public VirtualButtonBehaviour Scenename;

// Use this for initialization

void Start()

    {

        VirtualButton = GameObject.Find("Next");

        VirtualButton.GetComponent<VirtualButtonBehaviour>().RegisterOnButtonPressed(OnButtonPressed);

        VirtualButton.GetComponent<VirtualButtonBehaviour>().RegisterOnButtonReleased(OnButtonReleased);

    }

public void OnButtonPressed(VirtualButtonBehaviour vb)

    {

        Debug.Log("Btn Pressed");

        SceneManager.LoadScene(Scenename);

    }

    public void OnButtonReleased(VirtualButtonBehaviour vb)

    {

        Debug.Log("Btn Released");

    }

}

AttachmentSize
Image icon eror.png58.02 KB

How to call a scene in unity using virtual buttons

August 17, 2021 - 3:32am #8

Hey there,

 

Don't worry! There are a very good video tutorial how to use Virtual Buttons in your projects. The most recent one I could find is this one: https://www.youtube.com/watch?v=Ckw4RKKVE3k

Also, I recommend going through the core samples, there's a scene that also uses the virtual buttons: https://assetstore.unity.com/packages/templates/packs/vuforia-core-samples-99026

Hope that helps!

 

Kind regards,

Patrick Scheper

Technical Community Manager

How to call a scene in unity using virtual buttons

August 17, 2021 - 3:07am #7

I've studied it and I want to ask how do I make a virtual button can call another scene? I'm very confused about setting it up, I've seen the tutorial but I failed. I've studied it and I want to ask how do I make a virtual button can call another scene? i need step by step to make it. I'm very confused about setting it up, I've seen the tutorial but I failed. I'm sorry if I confused you with my explanation

what I want to do is like in this video

https://www.youtube.com/watch?v=kEflBg8Ifzs

How to call a scene in unity using virtual buttons

August 16, 2021 - 6:22am #6

Hey there,

 

In simple terms, virtual buttons are areas that you setup on your image target. These areas are being triggered when the underlying feature points are being obstructed.

As you can see above, that's the astronaut image from the samples. When added to the developer portal, you can see those yellow feature points. When these are obstructed, let's say, with your hand, the event of the virtual button is called.

To understand more about the difference between virtual buttons and UI buttons, follow this article: https://library.vuforia.com/articles/Solution/How-To-Implement-Virtual-Buttons.html



Kind regards,

Patrick Scheper

Technical Community Manager

How to call a scene in unity using virtual buttons

August 13, 2021 - 8:36am #5

is virtual button the same as UI button for function and code? and if i want to press virtual button from scene a to scene b i have to create a new scene just like UI button ? I'm still confused about that part

How to call a scene in unity using virtual buttons

July 21, 2021 - 12:10am #4

Hi,

you can use the call embedded in any ohter code:

here only the relevant part of the code for calling of scene

using UnityEngine.SceneManagement;

...

sceneName = "ModelTargetDatabaseUseSample";

SceneManager.LoadScene(sceneName, LoadSceneMode.Single);// LoadSceneMode.Additive);

....

For additional in´formation you can  check the article How To Implement Virtual Buttons and review the implementation  in the asset  Vuforia Core Samples  -> folder Assets/SamplesResources/scenes the scene 3-VirtualButtons. The script  (where the OnButtonPressed and OnButtonReleased are defined) is here the VirtualButtonEventHandler.cs  - it broadcast an message (HandleVirtualButtonPressed) to the object (ImageTarget) the its child objects

BR

Vuforia Engine Support

How to call a scene in unity using virtual buttons

July 16, 2021 - 12:59pm #3

can i use that code function in user defined target method?

How to call a scene in unity using virtual buttons

July 16, 2021 - 4:14am #2

Hi,

you can call a code which will load a scene from any UI buttons but also form a Virtual button defined to particular Image Target.

The code is simple:

...

using UnityEngine;

using Vuforia;

using UnityEngine.SceneManagement;

...

//later in some the call of scene in e.g OnGUI() function

void OnGUI()

    {

        // Display current 'scanning' status

        GUIStyle myButtonStyle = new GUIStyle(GUI.skin.button);

        myButtonStyle.fontSize = 40;

        myButtonStyle.normal.textColor = Color.red;

        myButtonStyle.hover.textColor = Color.green;

        var sceneName = "CloudRecoTestCase";

        //var sceneName = "ClaoudRecoTestCustomer1";

        if (GUI.Button(new Rect(100, 100, 700, 50), "-->> "+ sceneName, myButtonStyle))

        {  print("Calling "+ sceneName);

            SceneManager.LoadScene(sceneName, LoadSceneMode.Single);// LoadSceneMode.Additive);

        }

        sceneName = "ModelTargetDatabaseUseSample";

       

        if (GUI.Button(new Rect(900, 100, 700, 50), "-->> " + sceneName, myButtonStyle))

        {

            print("Calling " + sceneName);

            SceneManager.LoadScene(sceneName, LoadSceneMode.Single);// LoadSceneMode.Additive);

        }

        //ModelTargetDatabaseUseSample

        if (GUI.Button(new Rect(100, 200, 700, 50), "Quit the Applicaiton", myButtonStyle))

        { print("Quit the Applicaiton");

            //Application.Quit();

            QuitGame();

        }



    }

So in your case you need to call you code from the script of the Virtual Button . For the virtual button you can also check:

1.)  The Vuforia Developer portal article : How To Implement Virtual Buttons

2.)  from the Virtual Buttons sample scene form the Vuforia Core Samples

Then open the scene 3-VirtualButtons in the folder Assets/SamplesResources/scenes and check one of the 4 Image Targets -to each Image Target there is Virtual button definition . e.g. Image_Target_Fissure - the button push and release behavior is defined in the script VirtualButtonEventHandler.cs

BR

Vuforia Engine Support

Log in or register to post comments