I’m trying to make a 2d adventure game where player moves from room and room, like a point and click adventure game. I was planning on making each room a scene. So lets say you enter a house, you move to another scene and when you leave the house, you return to the original scene but in front of the house. My initial plan was to track what the previous scene was and move the spawn point accordingly but I have a felling it might get really hectic. What would be the best way to approach this?
If your scenes are very light weight I terms of memory use, if you can squeeze all your textures onto a reasonable amount of atlas’. I would consider keeping them all in one scene. It would save loading time. Especially if you are reloading textures and sounds that have already been loaded via the previous scene.
That being said, lets say you can’t. You have a bunch of atlases total, and having a scene per room is the best option. Then, I would do this…
Lets say you have a room, scene, in a house. The house may contain an upstairs, downstairs, living room and kitchen. This, I would consider putting in one scene as this house, would most likely share the same sound effects, and be small enough in textures, that you could fit them onto one atlas. … That being said, you must now load in different rooms…
So, lets assume for the house, you want to keep one scene, for all the rooms. I would place a trigger, in the doorway that, for instance, leads from the living room to the kitchen. Once the player, in the living room, enters this trigger, (which is at the right side of the camera view), we must now consider how to transition from room to room in a way that is appealing to the user…
Player enters trigger, now, initiate room swap.
RoomSwap()
Fade to black.
Keep camera stationary.
Swap texture UV points to now represent kitchen.
Change player position to the left side of the camera view, so he sits in the kitchen doorway.
Fade out black.
Now you have the same Unity scene, but a whole new room. Very theatric if you will. By keeping the same scene you will save a lot of loading time. If you have long load times because you change the Unity Scene, and it has to load each level, each time you enter and leave a room, your user may become impatient.
Now, lets say you want to leave the house. Outside may have a whole new atlas, materials, sounds etc. so now, it may be worth changing scenes.
I thought about having everything on 1 scene but I was reading somewhere that it may cause problems down the road. My scenes are probably not going to be very big but I thought it would be good practice to learn how to do it. The only issue I ran into was changing the spawn point depending on which scene you entered from.
I’ll have to reconsider to have a larger scene. It’ll be a lot easier to transition from neighborhood to house by moving the position instead of changing from scene to scene. Splitting every room in a house might be a bit much but I’ll keep your room swap in mind though.
Put this on your door object, set the positions and level name (actual scene name) in the inspector. You could also incorporate a fade prior to changing the players position, that way you wont see the player snap to some weird vector prior to the scene loading.
public class ChangeScenes : MonoBehavior {
public string sceneName;
public float xPosition;
public float yPosition;
void OnCollisionEnter(Collision other) {
if(other.collider.tag == "Player") {
other.transform.position = new Vector3(xPosition, yPosition, 0);
Application.LoadLevel(sceneName);
}
}
}
I am suggesting one scene for house (3 rooms), one scene for nieghbourhood (3 sections),… Etc.
Of course, this all depends on what your actual set up is like. Perhaps each “room”/section is so rich in content, a new scene for each section is your only option. However, the best practice is to condense, and make the engine run as light as possible. Still tho, many variables exist and you have to do what’s best for you.