Question by
BrightobenPlaysbenferraz · Jun 01, 2020 at 07:24 AM ·
c#gamescorescore systemlimit
Anyway To Set A Specific Part Of Code To A Scene?
Hey, is there any way I can set a part of code in my script to run in only one scene? you can see the code below;
Basically what I'm trying to do is set a specific score limit to a scene as I want to make it rise as you go through levels.
or if there is any other way of doing this please let me know!
public static void Score() { if (score >= 50) LevelCompleteWindow.ShowStatic();
if (score >= 50) {
Time.timeScale = 0;
}
else {
Time.timeScale = 1;
}
Comment
Best Answer
Answer by SteenPetersen · Jun 01, 2020 at 07:24 AM
You can check which scene you are in with SceneManager.GetActiveScene. So you could do something like:
private static float score;
[SerializeField] private static Dictionary<string, float> scenesAndMaxScores = new Dictionary<string, float>()
{
{"firstScene", 50},
{"secondScene", 100},
{"thirdScene", 150}
};
private void Start()
{
score = 1000;
Score();
}
public static void Score()
{
Scene scene = SceneManager.GetActiveScene();
float maxScore = scenesAndMaxScores.FirstOrDefault(x => x.Key == scene.name).Value;
score = Mathf.Clamp(score, 0, maxScore);
Debug.Log(score);
// do whatever
}
Answer by BrightobenPlaysbenferraz · Aug 10, 2020 at 10:58 AM
Thank you so much for the help been trying to get over this forever!