- Home /
Reuse Scenes just changing some variables??
Hi,
I have a Scene that I would like to reuse just changing some values such number of enemies, speed etc, depending on which level the player are, i.e:
Level 1: 10 enemies Level 2: 15 enemies
But I also want the user can select which level to play Does any one have an Idea on how to do it?
I prefer to do it this way instead of change the values and save it as other scene in oreder to save space.
Regards
Answer by Gizmoi · Jan 28, 2013 at 10:16 PM
I assume the number of enemies is a variable stored somewhere in a script in the scene?
Why not have a static script, or persistent GameObject, that is told how many enemies to spawn before loading the level, and when you load your scene, pull the relevant information from it?
For example:
static class LevelData
{
public static int m_NumEnemies = 0;
public static float m_Speed = 0;
}
Example difficulty selection:
if (difficulty == Difficulty.Easy)
{
LevelData.m_NumEnemies = 5;
LevelData.m_Speed = 2.5f;
}
Application.LoadLevel("NextLevel");
Example player class:
class Player : MonoBehaviour
{
float speed = 0;
void Awake()
{
speed = LevelData.m_Speed;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613091741im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Get name of Scene-file from MonoBehaviour 1 Answer
Shared canvas for some scenes 1 Answer
How to make the level screen????? 0 Answers
One Location Game (with Scenes Loaded and Disabled) 0 Answers
accesing objects variables 1 Answer