I am trying to get a character and its camera to another scene with this code:
public GameObject m_MyGameObject;
public GameObject m_MyGameCam;
void OnTriggerEnter(Collider collision)
{
if (collision.gameObject.name == "Plane")
{
if (m_MyGameObject != null && m_MyGameCam != null)
{
SceneManager.MoveGameObjectToScene(m_MyGameObject, SceneManager.GetSceneByName("lvlfirstenemy"));
Object.DontDestroyOnLoad(m_MyGameCam);
}
SceneManager.LoadScene(1);
}
}
Though, I continue to get an error (even with problem solving) that the destination scene is not valid…
I know that i cannot reference it while the scene is inactive, so i tried to add the code right before moving the objects:
SceneManager.SetActiveScene(SceneManager.GetSceneByName(“lvlfirstenemy”));
and another error appears: SceneManager.SetActiveScene failed; invalid scene.
The scene name is correct… any help?