Hi everyone, I was confused by the sample code provided by unity tutorials,like this:
[RPC]
void LoadLevel(string levelName, int levelPrefix)
{
lastLevelPrefix = levelPrefix;
// There is no reason to send any more data over the network on the default channel,
// because we are about to load the level, thus all those objects will get deleted anyway
Network.SetSendingEnabled(0, false);
// We need to stop receiving because first the level must be loaded.
// Once the level is loaded, RPC's and other state update attached to objects in the level are allowed to fire
Network.isMessageQueueRunning = false;
// All network views loaded from a level will get a prefix into their NetworkViewID.
// This will prevent old updates from clients leaking into a newly created scene.
Network.SetLevelPrefix(levelPrefix);
Application.LoadLevel(levelName);
yield;
yield;
// Allow receiving data again
Network.isMessageQueueRunning = true;
// Now the level has been loaded and we can start sending out data
Network.SetSendingEnabled(0, true);
// Notify our objects that the level and the network is ready
foreach (GameObject go in GameObject.FindObjectsOfType(typeof(GameObject)))
go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}
I don't know why use tow yield here,and I'm not sure when will the Application.LoadLevel() return. I guess it won't return untill the level is loaded completely because there is another function Application.LoadLevelAsync().But the yield instruction realy made me confused. very greatful if someone can make it more clear.