Make a new level! - smkmth/RPG2 GitHub Wiki
My level manager might seem a little unintuitive at first - it builds the level using data from a scriptable object instead of having all the elements in the scene already in place - which means there are a couple more steps required to build a new level.
i am doing this for a reason - because each level is populated by a script, i can dynamically change what items show up there, what people show up there, where the player appears ect ect.
however - i am not like expert coder or whatever, so i might have made things over complicated or whatever, still learning. i wrote this guide for making a new level for myself if i forget how it works later on, or i am banging my head trying to work out why somthing dosnt work now ect.
- make a new scene
- Add scene to build order
- make a new level data scriptable object
- fill in who is in the scene and where they are on the level data object.
- Give the level data object a name, somthing distinctive.
- make sure to fill in the player entrance - thats where the player will spawn.
- inside the _app object is a child called manager. navigate to that in the inspector
- on this manager object is a component called levelhandler.
- this component has a list called levels. put the leveldata scriptable object inside that list.
your done, a level will now exist and be in the game. setting up a hook to navigate to that level is also somewhat easy. here is an example - to demonstrate where all the code goes and stuff.
- make an object in the level - somewhere approprate as an exit portal - like a door or somthing.
- (optional) Add a marker on the ground infront of the object, so the player dosnt just walk halfway into it while interacting.
- add the component 'Interactable'.
- drag the marker you made to the interactable marker field.
- add the component 'Area Exit'
- fill in the two fields - one with a string saying what scene you want this exit to lead to
- the other should say what leveldata you want to load.
- SPELL CAREFULLY - its litearally searching through the built scenes and level datas for the correct thing to load
A few notes
- at the moment each level data has only one playerEntrance - which means multiple leveldata files need to be used if you want the player to appear at a different door. might change it later but seems fine for now.