Hi all,
Currently I am teleporting my player from a scene to another depending on the current scene, using this (just posting part of the code) :
public string[] levelNames = {"level_1", "level_2", "level_3", "level_4", "level_5", "level_6"};
void Limbo()
{
SceneManager.LoadScene("limbo");
}
if (PlayerData.Lives <= 0)
if (SceneManager.GetActiveScene().name == levelNames[0])
{
Limbo();
}
if (SceneManager.GetActiveScene().name == levelNames[1])
{
Limbo();
}
And so on and so onā¦for every single level (6 so far). Isnāt there a better way to do it? Using build Index is the same, and I canāt use || to actually make the code shorter.
It works as it should but it makes the code pretty big and chaotic.
Ty all in advance
There are various types of ālimboāā¦limbo 1, limbo 2 etcā¦first 3 levels would load limbo 1 if you get to 0 lives, the other 3 levels would load limbo 2 and so onā¦(I have a void Limbo2() function too in the actual code, and I will have to make more).
I canāt use || because it says ācannot apply the operator || to bool and string.ā
Okay, the error then must have been how you typed it.
did you try to type something like : if(this_string == this_otherString1 || this_otherString2) ?
With string or build index, you could do:
if (index >= x && index <= y)
or
if(scene name == string_array[0] || scene_name == string_array[1]) etc.
Sorry I didnāt use code tags, hopefully that makes sense.
If you only have 6 levels, I would not even worry about something more complex than that.
edit: you could do this, too. (not sure if this is truly useful)
Well 6 levels for now, I aim for 40+
And yeah, it was a typing error!
I was writing
if (scene_name == string_array[0] || string_array[1])
instead of
if(scene_name == string_array[0] || scene_name == string_array[1]) etc.