system
1
I’m having an issue with creating a spawn point after a level has loaded. So basically, after level 1, it loads level two and loads the default spawn, then after a bonus level, its suppose to return to the 2nd level but with a different spawn. however it keeps using the default spawn. heres my script:
function OnLevelWasLoaded (level : int) {
if(level == 2)
{
loadedPipeLev = true;
}
if(level == 1 && loadedPipeLev == true)
{
Debug.Log("loaded level 2");
transform.position = level2Spawn.transform.position;
}
}
any help would be greatly appreciated.
Put the information about what spawns and what doesn’t and where in a script on an empty GameObject, and then in your preloader scene (in its start function) use
DontDestroyOnLoad(gameObject);
to stop it getting despawned every time you load a level.
This way you can carry data between scenes, without having to do something cumbersome like use PlayerPrefs.
You can save the spawn points coords using PlayerPrefs like so:
PlayerPrefs.SetFloat("SpawnPosX", 10.0);
PlayerPrefs.SetFloat("SpawnPosX", 10.0);
PlayerPrefs.SetFloat("SpawnPosZ", 10.0);
or using an gameObjects Vector3 with preventing its destruction:
function Awake ()
{
DontDestroyOnLoad (transform.gameObject);
}
Or you save using one of this methods an int to indicate an spawn pont in the players awake/start function.
hope that points you an solution 