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
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!
you can instantiate prefabs:
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.
Unity - Scripting API: SceneManagement.LoadSceneMode.Additive could also be used to load multiple scenes op top of eachother (additive), but i think this is more advanced.
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?