diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 3b70cd3..3a0cc5a 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -3734,20 +3734,12 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] - m_AddedGameObjects: - - targetCorrespondingSourceObject: {fileID: 3032075919872812610, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} - insertIndex: -1 - addedObject: {fileID: 4910321061857220296} + m_AddedGameObjects: [] m_AddedComponents: - targetCorrespondingSourceObject: {fileID: 809911508645467208, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} insertIndex: -1 addedObject: {fileID: 1683288374126251323} m_SourcePrefab: {fileID: 100100000, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} ---- !u!4 &1683288374126251322 stripped -Transform: - m_CorrespondingSourceObject: {fileID: 3032075919872812610, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} - m_PrefabInstance: {fileID: 1683288374126251321} - m_PrefabAsset: {fileID: 0} --- !u!114 &1683288374126251323 MonoBehaviour: m_ObjectHideFlags: 0 @@ -3891,7 +3883,7 @@ PrefabInstance: serializedVersion: 2 m_Modification: serializedVersion: 3 - m_TransformParent: {fileID: 1683288374126251322} + m_TransformParent: {fileID: 0} m_Modifications: - target: {fileID: 144529238244638330, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3} propertyPath: m_LocalPosition.x @@ -3950,11 +3942,6 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3} ---- !u!4 &4910321061857220296 stripped -Transform: - m_CorrespondingSourceObject: {fileID: 144529238244638330, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3} - m_PrefabInstance: {fileID: 4910321061857220295} - m_PrefabAsset: {fileID: 0} --- !u!1001 &5796191506433166633 PrefabInstance: m_ObjectHideFlags: 0 @@ -4822,6 +4809,7 @@ PrefabInstance: SceneRoots: m_ObjectHideFlags: 0 m_Roots: + - {fileID: 4910321061857220295} - {fileID: 1683288374126251321} - {fileID: 1536317696} - {fileID: 4158834148864819266} diff --git a/Assets/Scripts/Multiplayer/NetworkedGameSetup.cs b/Assets/Scripts/Multiplayer/NetworkedGameSetup.cs index 36b3275..10c3827 100644 --- a/Assets/Scripts/Multiplayer/NetworkedGameSetup.cs +++ b/Assets/Scripts/Multiplayer/NetworkedGameSetup.cs @@ -5,6 +5,7 @@ using System.Linq; using Unity.Netcode; using UnityEngine; using UnityEngine.SceneManagement; +using static UnityEditor.Experimental.GraphView.GraphView; public class NetworkedGameSetup : NetworkBehaviour { @@ -34,6 +35,13 @@ public class NetworkedGameSetup : NetworkBehaviour else players = GetPlayers(playerIds); + StartCoroutine(LateSetupProcedue(players)); + } + + private IEnumerator LateSetupProcedue(GameObject[] players) + { + yield return new WaitForSecondsRealtime(0.01f); + InitRope(players); InitUpgrader(players); @@ -43,13 +51,7 @@ public class NetworkedGameSetup : NetworkBehaviour private GameObject[] GetPlayers(List playerIds) { - GameObject[] players = new GameObject[playerIds.Count]; - - for (int i = 0; i < playerIds.Count; i++) - { - ulong playerId = playerIds[i]; - players[i] = NetworkManager.SpawnManager.SpawnedObjects[playerId].gameObject; - } + GameObject[] players = NetworkManager.SpawnManager.SpawnedObjects.Select(x=>x.Value.gameObject).ToArray(); return players; } @@ -70,10 +72,8 @@ public class NetworkedGameSetup : NetworkBehaviour private void InitRope(GameObject[] players) { - RopeSimulator ropeSim = GetComponentInChildren(); - // Assuming 2 players - ropeSim.BuildRope(players[0].GetComponent(), players[1].GetComponent()); + RopeSimulator.instance.BuildRope(players[0].GetComponent(), players[1].GetComponent()); } private void InitUpgrader(GameObject[] players) diff --git a/Assets/Scripts/Rope/RopeSimulator.cs b/Assets/Scripts/Rope/RopeSimulator.cs index bfed76f..6aac7f3 100644 --- a/Assets/Scripts/Rope/RopeSimulator.cs +++ b/Assets/Scripts/Rope/RopeSimulator.cs @@ -70,6 +70,20 @@ public class RopeSimulator : MonoBehaviour Dictionary colliderToSquezeForce = new(); + public static RopeSimulator instance; + + private void Awake() + { + if (instance == null) + { + instance = this; + } + else + { + Destroy(instance); + } + } + private void Start() { // Example of using rope builder @@ -178,6 +192,8 @@ public class RopeSimulator : MonoBehaviour private void OnDestroy() { + if (start == null || end == null) return; + start.playerInput.ropeLengthShrinken -= ShrinkenRope; end.playerInput.ropeLengthShrinken -= ShrinkenRope;