Pass parameters to an object in another scene

I want to load a new scene (using `Application.LoadLevel()`) but I would like to pass a parameter to an object in that scene. Is that possible?

Or will I have to write what I need to the PlayerPrefs and then read them on the new scene?

sebas's answer is correct and you have other ways to do this too. you can have a static class called SceneProperties and have a list of properties in it or have a list in it to set it's items. unfortunately none of the methods like LoadLevel and Instantiate don't get additional parameters to send to new objects or all objects in the new scene. so you need to store data in a static class or a GameObject that won't destroy with the scene or put the in prefs. the first method is the best and fastest one and the last one is the slowest and even can fail and is not good for web games. you can easily get exceptions with player prefs so use static classes. unfortunately you can not get the name of current scene and you should use another way to find out what scene you are in. to create static classes and variables use "static" keyword. you don't need to create them and one instance of them will be created at the first frame or even before it and you can set it's properties or add items to it's lists or call it's methods. they are the best solution for creating managers.

Maybe don't destroy an object from the old scene by using Don'tDestroyOnLoad and then assigning a variable of that object to something else in your new scene in a Start() or Awake() function? That usually should do the trick.

You can create an object in first scene, attach a sript to it and sen value of variable in this script. For example if you want to send user login script attachet to game object that will survife after second scene load should be:

// User login:

public var userLogin : String;

function Awake() {

// Do not destroy this game object:

DontDestroyOnLoad(this);

}

Set userLogin in first scene and read in second.

Complete example can be found in my blog http://unity-tutorials.blogspot.com/. Listing 20 and 21.