Hi everyone!
I haven’t used Unity in a while and I’m having a bit of trouble with reentry.
I have tried creating two scenes (both are in the hierarchy, one starts loaded, the other not) and I want to be able to go forth and back between the two.
The first one (initialy loaded) is a menu scene with GUI elements that load a FPS scene when you click the right button.
The second one (initialy unloaded) is a FPS scene with character control, that goes back to the menu scene when the character collides with an element.
The button clicking and the collision both work fine.
Problem is the following :
When I’m back to the menu, the Toolbar buttons do not function (not even the roll over display) and I can’t click on anything because the cursor lock keeps running.
The InternalLockUpdate() is called in Update() in CharacterController.cs, which is bound to the character present in the FPS Scene hierarchy.
private void InternalLockUpdate()
{
if (Input.GetKeyUp(KeyCode.Escape))
{
m_cursorIsLocked = false;
}
else if (Input.GetMouseButtonUp(0))
{
m_cursorIsLocked = true;
}
if (m_cursorIsLocked)
{
UnlockCursor();
}
else if (!m_cursorIsLocked)
{
LockCursor();
}
}
private void UnlockCursor()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void LockCursor()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
This is the system that returns the user to the menu
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.gameObject == avatar)
{
StartCoroutine(SceneSwitch());
}
}
IEnumerator SceneSwitch()
{
AsyncOperation load = SceneManager.LoadSceneAsync("Menu", LoadSceneMode.Single);
yield return load;
Debug.Log("test");
SceneManager.UnloadSceneAsync("Planet_Abydos");
}
By the way, “test” never shows up in the Log, which might be a clue…
This is the code that loads the FPS scene
if (GUILayout.Button("Explore Abydos"))
{
SceneManager.LoadScene("Planet_Abydos");
};
Thanks in advance for all your very welcomed help