public void OnSpawnerReady(bool alreadyFinishedSceneSetup, SceneSpawner sceneSpawner) { if (!alreadyFinishedSceneSetup) { float positionX = Random.Range(-6.0f, 6.0f); float positionY = Random.Range(-6.0f, 6.0f); sceneSpawner.SpawnForPlayer(0, new Vector3(positionX, positionY, 0), Quaternion.identity); sceneSpawner.PlayerFinishedSceneSetup(); } }
public void OnSpawnerReady(bool finishedSetup, SceneSpawner sceneSpawne) { if (!finishedSetup) { if (NetworkClient.Instance.IsHost) { sceneSpawne.SpawnForPlayer(0, 0); } else { sceneSpawne.SpawnForPlayer(0, 1); } sceneSpawne.PlayerFinishedSceneSetup(); } }
// OnSpawnerReady(bool alreadySetup) method is added to handle the On Ready Event. public void OnSpawnerReady(bool alreadySetup, SceneSpawner sceneSpawner) { Debug.Log("OnSpawnerReady " + alreadySetup); // Check alreadySetup to see if the scene has been set up before. // If it is true, it means the player disconnected and reconnected to the game. // In this case, we should not spawn a new Player GameObject for the player. if (!alreadySetup) { // If alreadySetup is false, it means the player just started the game. // We randomly select a SpawnPoint and ask the SceneSpawner to spawn a Player GameObject. // we have 1 playerPrefabs so playerPrefabIndex is 0. // We have 4 spawnPoints so we generated a random int between 0 to 3. int spawnPointIndex = Random.Range(0, 3); sceneSpawner.SpawnForPlayer(0, spawnPointIndex); // Tell the spawner that we have finished setting up the scene. // alreadySetup will be true when SceneSpawn becomes ready next time. sceneSpawner.PlayerFinishedSceneSetup(); } }
// SceneSpanwer events public void OnSpawnerReady(bool finishedSceneSetup, SceneSpawner sceneSpawner) { // scene has not been set up. spawn a car for the local player. if (!finishedSceneSetup) { /* * assign different spawn points for the players in the room * This is okay for this tutorial as we only have 2 players in a room and we are not handling host migration. * To properly assign spawn points, you should use roomPropertyAgent or custom room data. */ if (NetworkClient.Instance.IsHost) { sceneSpawner.SpawnForPlayer(0, 1); } else { sceneSpawner.SpawnForPlayer(0, 0); } // tells the SceneSpawner the local player has finished scene setup. sceneSpawner.PlayerFinishedSceneSetup(); } }
public void OnSpawnerReady(bool alreadySetup, SceneSpawner sceneSpawner) { Debug.Log("OnSpawnerReady " + alreadySetup); if (!alreadySetup) { if (NetworkClient.Instance.IsHost) { GameObject go = sceneSpawner.SpawnForPlayer(0, 0); Debug.Log("OnSpawnerReady created GameObject" + go.name); } else { GameObject go = sceneSpawner.SpawnForPlayer(0, 1); Debug.Log("OnSpawnerReady created GameObject" + go.name); } sceneSpawner.PlayerFinishedSceneSetup(); } }