I have variable that I need to save and load between 2 scenes.
So this is what I'm trying:
First script:
public class s1sc : MonoBehaviour
{
public string playername;
public static s1sc Instance;
void Awake ()
{
if (Instance == null)
{
DontDestroyOnLoad(gameObject);
Instance = this;
}
else if (Instance != this)
{
Destroy (gameObject);
}
}
Second script:
public class s2sc : MonoBehaviour
{
public string pn;
void Start ()
{
pn = s1sc.Instance.playername;
}
}
And it doesn't work fine. What is the problem??