Scene Connecting

Alright,

So I ran into a bit of a problem with the linking.

I know that when creating a new level (new star system in my case) you place the player down where they will arrive/start.

Well going to the new star system works beautifully. My question is, when I return back through the gate, I start where the player first starts on the otherside of the system.

How can I correct this to get the player to actually arrive at each gate?

You need at least one object to maintain game state across levels.

Often people have a GameObject called "GameController" or "GameManager" or something like that, that performs game logic and keeps track of information that needs to be passed from level to level. To keep the object from going away, call DontDestroyOnLoad on it.

The tricky part is making sure that you only have one of these objects around. You don't want the first scene to create a new one when the player returns to it. There are various ways around this. See the Unity Wiki's article on Singletons for some good examples. (That code also solves another problem for you, which is how your scripts can easily and efficiently finding the manager object to use.)

In each level you can place some spawn points on the locations where the player should be able to appear. You could have multiple spawn points with different names. You can make a spawn point script that you can attach to an empty game object to make it a spawn point.

You need to have a persistent object (one that is not destroyed when you load a new scene). When entering a gate, you tell this object at which named spawn point in the new scene the player should be spawned at. The persistent object could either be some controller object, or it could just be the player himself.

You can create persistent objects either by using Object.DontDestroyOnLoad. Alternatively, if you only need some persistent data and not a whole gameobject, you can store the data in static variables of a class.

When the new level has loaded, the persistent object spawns the player at the right spawn point, of if the player himself is persistent, you can just move him to the right point. You can use the OnLevelWasLoaded function on the persistent object for that.

The best thing is probably to not create a new player for each scene you load, so tag it with DontDestroyOnLoad if you haven't done so already.

Next, in the player script you would want to put a variable stating if it should start at the start or at a gate, if if it should start at the gate, then define which gate (if you have more than one gate). So when a new scene loads, it will look for if it should place the player at the gate or at the start and place it where it should be.

I needed to communicate between levels, so I wrote a C# script with nothing but static members and methods. I had a private Dictionary to hold named data, accessor methods to add, remove, or change the stored data.

Because it didn't have anything but static methods, I didn't inherit from Monobehaviour. I had to put it in the standard assets/scripts folder for it to be accessible to other scripts.

This has the advantage of not requiring any special game objects or set up in the Unity editor.

But… if in my scene the player destroy an enemy (gameobject)… when exit ed re-enter (load scene) in this scene… i dont want the destroyed gameobjects…