Hi!!!
I want to ask how to call another scene but using virtual button?, I use user defined target method
- Sort Posts
- 24 replies
- Last post
How to call a scene in unity using virtual buttons
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
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
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
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
Attachment | Size |
---|---|
![]() | 369.72 KB |
How to call a scene in unity using virtual buttons
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
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
Attachment | Size |
---|---|
![]() | 880.6 KB |
How to call a scene in unity using virtual buttons
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
Attachment | Size |
---|---|
![]() | 153.05 KB |
![]() | 7.54 MB |
How to call a scene in unity using virtual buttons
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
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
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
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");
}
}
Attachment | Size |
---|---|
![]() | 58.02 KB |
How to call a scene in unity using virtual buttons
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
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
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
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
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
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
i'll try it, thank you so much for helping me^^