From 9887ee0266139dbe520a2e2b84d6def824e173f5 Mon Sep 17 00:00:00 2001 From: Sveske_Juice Date: Sun, 17 Mar 2024 19:59:34 +0100 Subject: [PATCH] Include enemy posisions in gamestate --- Assets/Scripts/Rope/GameState.cs | 3 +++ Assets/Scripts/Rope/RopeSimulator.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Rope/GameState.cs b/Assets/Scripts/Rope/GameState.cs index c4887a9..cffecae 100644 --- a/Assets/Scripts/Rope/GameState.cs +++ b/Assets/Scripts/Rope/GameState.cs @@ -1,10 +1,12 @@ using Unity.Netcode; +using UnityEngine; [System.Serializable] public struct GameState : INetworkSerializable { public int tick; public NetworkRope nrope; + public Vector2[] enemyPositions; public override int GetHashCode() { @@ -20,6 +22,7 @@ public struct GameState : INetworkSerializable public void NetworkSerialize(BufferSerializer serializer) where T : IReaderWriter { serializer.SerializeValue(ref tick); + serializer.SerializeValue(ref enemyPositions); nrope.NetworkSerialize(serializer); } } diff --git a/Assets/Scripts/Rope/RopeSimulator.cs b/Assets/Scripts/Rope/RopeSimulator.cs index ef49443..4078fee 100644 --- a/Assets/Scripts/Rope/RopeSimulator.cs +++ b/Assets/Scripts/Rope/RopeSimulator.cs @@ -4,7 +4,6 @@ using System.Linq; using Unity.Netcode; using UnityEngine; using UnityEngine.Assertions; -using Utilities; using UnityUtils; public class RopeSimulator : NetworkBehaviour @@ -315,7 +314,8 @@ public class RopeSimulator : NetworkBehaviour { GameState localState = new() { tick = currentTick, - nrope = Rope.ToNetworkRope(this.rope) + nrope = Rope.ToNetworkRope(this.rope), + enemyPositions = GameObject.FindObjectsByType(FindObjectsSortMode.None).Select(e => new Vector2(e.transform.position.x, e.transform.position.y)).ToArray() }; return localState;