- Home /
How do i make levels?
Dear Community, i am making a game of my own, (note:- i am a beginner) but i do not know how to make missions, i plan to make different games for it, but adding the same map over and over again is painful, so is there a thing i can use to make different levels? for i am very new, first started unity about 4 days ago
Answer by rage_co · May 26, 2021 at 05:00 AM
I am somewhat of a beginner myself, but i think the answer to your queries are Scenes and prefabs. You can drag any GameObject from your Scene view to the assets section and it will get converted into a prefab. you can easily drag and drop objects into your Scene view to create levels. Also, if you open and edit a prefab, the changes will be applied to all the objects created using the prefab.
You can use scenes to create different levels. After that you can C# scripts to load scenes. To load a scene, first add this at the top of your script:
using UnityEngine.SceneManagement;
after that you can manage the order of scenes in File>Build Settings in the Unity editor and then easily load scenes with this command:
SceneManager.LoadScene(<build index of the target scene goes here, scene 1 has an index of 0, scene 2 has an index of 1 and so on>);
If you want to load a scene which is a set number of index numbers before or after your current scene use this:
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + <difference in build index of scenes>);
you can use - insted of plus or even * or / if it has some purpose.
Hope this helps!
rage_co, thanks for your reply, i will try it, but do you mean when i copy the terrain data below the scene and put them to the assests folder, once i add them to another mission or scene it will be the same, do you mean that?
I did not fully understand your question, but It will create an exact replica of any object you create a prefab of.
i mean that when we copy the terrain file in assets and put it in another project the same map will be back???? thats what i meant
i think yes. prefab assets can be imported between different projects, however if you are using components or assets that aren't in the new project but are in the prefab (for example some movement script), be sure to import that too.
I am not completely sure but that should work
Answer by Arano · Jun 02, 2021 at 07:56 AM
you can instantiate prefabs: https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
as a script (in your menu scene maybe?) this is quite easy to setup, below some psuedo code:
public GameObject levelBackgroundPrefab; //can be set in the editor inspector
public GameObject level1ObjectsPrefab; //can be set in the editor inspector
public GameObject level2ObjectsPrefab; //can be set in the editor inspector
void StartLevel(int level)
{
GameObject levelInstance = instantiate(levelBackgroundPrefab);
levelInstance.position = 10,10,10; //example
levelinstance.getcomponent<weather> = snow; //example
GameObject objects
if (level == 1)
objects = instantiate(level1ObjectsPrefab);
if (level == 2)
objects = instantiate(level2ObjectsPrefab);
//do stuff
object.getcomponent<player>.hp = hplastlevel; //example
}
or you could just build the maps using prefabs, if scene A has prefab A and scene B also has prefab A, changing the prefab A in any of the 2 scenes (should) change it in both of the scenes.
https://docs.unity3d.com/ScriptReference/SceneManagement.LoadSceneMode.Additive.html could also be used to load multiple scenes op top of eachother (additive), but i think this is more advanced.
Your answer
Follow this Question
Related Questions
How do I change scenes from triggers in UNity 1 Answer
Unity game level design patterns 0 Answers
How to add multiple levels? 3 Answers
players create level 0 Answers
Multiple Scenes for Multiple Levels, or One Scene with all Levels? 1 Answer