How can I import number from another scene? For example:
scene1 script
if(...) {
a = 1;
} else {
a = 0;
}
How to import a
to the next scene?
How can I import number from another scene? For example:
scene1 script
if(...) {
a = 1;
} else {
a = 0;
}
How to import a
to the next scene?
You can do this by using a as a static variable. it will keep the value.
public static int a;
The way I do this is by making the scene load async, and passing the value through code to the object that's supposed to receive it in the next scene:
var valueToPass = 2;
var asyncOp = SceneManager.LoadSceneAsync("otherScene");
asyncOp.OnCompleted += () =>
{
// this code runs once the second scene is loaded
FindObjectOfType<SomeOtherObject>().PropertyToFill = valueToPass;
}
I wrote the code off the top of my head, it probably won't compile (didn't have Unity on hand to test it) but that's the general idea.