VrGrabber icon indicating copy to clipboard operation
VrGrabber copied to clipboard

Change scene when object is grabbed.

Open ghost opened this issue 5 years ago • 1 comments

Hello all, I've a question:

Is it possible to go to another scene when you grab a object with your controller? I've seen in the test scene in the inspector that there's a "On Grabbed" section (picture) where you can select scenes. I've tried that, but no success. Can anyone help me with this. I'm new to programming and Unity so I don't really know how to do this. (I'm on the Oculus Go.) picture of inspector

ghost avatar Jan 19 '19 16:01 ghost

Hey @Robbin12392

yes it is possible and not that complicated. First you need a class with a public method containing the SceneManager.LoadScene() Make sure you use UnityEngine.SceneManagment on top of you script and don't forget to drag the scene you want to load into you Build Settings. After this is done, go to the grabbable component and click the + on the event you want to load the next scene. Now just drag the SceneLoader Component into the slot an select the LoadScene() Method. Everything should look like this.

Hope this helps! Best regards

sceneload

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneLoader : MonoBehaviour
{
    //make a public method
    public void LoadScene()
    {
        //Dont forget to put the scene into the build settings
        // than take the index to load scene 1
        SceneManager.LoadScene(1);

        // or you can use a string to load a new scene

        //SceneManager.LoadScene("name-of-scene", LoadSceneMode.Single);
    }
}

nothingAD avatar Apr 11 '19 14:04 nothingAD