using System; using System.Collections; using System.Collections.Generic; using Unity.Netcode; using UnityEngine; using UnityEngine.SceneManagement; public class NetworkedGameSetup : NetworkBehaviour { [SerializeField] private GameObject PlayerPrefab; private RopeSimulator RopeSim; private void Start() { DontDestroyOnLoad(this); NetworkManager.Singleton.SceneManager.OnLoadEventCompleted += SceneLoaded; } private void SceneLoaded(string sceneName, LoadSceneMode loadSceneMode, List clientsCompleted, List clientsTimedOut) { StartSetupProcedure(clientsCompleted); } private void StartSetupProcedure(List playerIds) { SpawnPlayers(playerIds); } private void SpawnPlayers(List playerIds) { NetworkManager.Singleton.SceneManager.OnLoadEventCompleted -= SceneLoaded; // Assuming only 2 palyers if (IsHost) { for (int i = 0; i < playerIds.Count; i++) { GameObject player = Instantiate(PlayerPrefab, Vector2.up * 3, Quaternion.identity); player.GetComponent().SpawnAsPlayerObject(playerIds[i], true); } } } }