Beispiel #1
0
    // This is the function which is used to load a fresh area. Any in-progress construction will be lost.
    // That shouldn't be a problem, because there should never be any leftover parts, and all constructed items
    // will be finished. Spawn point for the player MUST be pre-determined and passed into this function.
    public static void LoadNewExplorationLevel(string sceneName, Vector3 spawnPos)
    {
        // Grab player objects, bring to scene root, set as nondelete.
        GameObject playerRefs = GameObject.Find("Player (Including All Menus)");
        GameObject player     = GameObject.FindGameObjectWithTag("Player");

        playerRefs.transform.SetParent(null);
        DontDestroyOnLoad(playerRefs);

        // Clear the loadedscenes dictionary.
        loadedScenes.Clear();

        // Then load the new scene and position the player.
        SceneManager.LoadScene(sceneName);
        player.transform.position = spawnPos;

        // And setup a new position tracking file for the new scene.
        SimpleData.CreateNewPositionFile(sceneName);
    }