I need to do a loading scene that load different level from saves,
i made a empty scene only with the main camera and added to it :
loading.js:
#pragma strict
function Start () {
var livello : String;
if(PlayerPrefs.GetString("Livello") != null)
livello = PlayerPrefs.GetString("Livello");
else
Application.LoadLevel("main menu");
if(livello.Equals("livello 2"))
Application.LoadLevel("main menu 2");
}
With this code unity gives me 2 errors:
GetString can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
ArgumentException: GetString can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.PlayerPrefs.GetString (System.String key) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/PlayerPrefsBindings.cs:73)
loading..ctor () (at Assets/Scripts/loading.js:2)