diff --git a/Assets/Prefabs/Networked/Enemies/EnemyBase.prefab b/Assets/Prefabs/Networked/Enemies/EnemyBase.prefab index 08ade7c..7ae1448 100644 --- a/Assets/Prefabs/Networked/Enemies/EnemyBase.prefab +++ b/Assets/Prefabs/Networked/Enemies/EnemyBase.prefab @@ -17,6 +17,7 @@ GameObject: - component: {fileID: -3563373198581541198} - component: {fileID: 5669020798899338457} - component: {fileID: 7025838755278696983} + - component: {fileID: 3458620527668384477} m_Layer: 0 m_Name: EnemyBase m_TagString: Enemy @@ -154,6 +155,7 @@ MonoBehaviour: m_EditorClassIdentifier: targets: [] ropeDistCheck: 1 + stopBeforeTargetOffset: 1 ropeCheckMask: serializedVersion: 2 m_Bits: 0 @@ -239,3 +241,16 @@ MonoBehaviour: objectsToDisable: - {fileID: -2259174063119120971} - {fileID: 5063378671874793948} +--- !u!114 &3458620527668384477 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7065654593080984807} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e071dd818c5a905209e31c2d66ea6390, type: 3} + m_Name: + m_EditorClassIdentifier: + spawnedId: -1 diff --git a/Assets/Scripts/Enemy/EnemySpawner.cs b/Assets/Scripts/Enemy/EnemySpawner.cs index 16ac391..6df06ab 100644 --- a/Assets/Scripts/Enemy/EnemySpawner.cs +++ b/Assets/Scripts/Enemy/EnemySpawner.cs @@ -30,6 +30,8 @@ public class EnemySpawner : NetworkBehaviour public static EnemySpawner instance; + private static int idCounter = 0; + private void OnEnable() { GameManager.OnPlayersReady += OnPlayersReady; @@ -131,6 +133,7 @@ public class EnemySpawner : NetworkBehaviour void SpawnEnemy(GameObject enemyPrefab) { GameObject enemy = Instantiate(enemyPrefab, GetRandomPointOnCircle(SpawnRadius), Quaternion.identity, SpawnedEnenmyHolder.transform); + enemy.GetComponent().InitialID = idCounter++; enemy.GetComponent().Spawn(); enemy.GetComponent().targets = players.Select(x => x.transform).ToArray(); diff --git a/Assets/Scripts/Utilities/NetworkID.cs b/Assets/Scripts/Utilities/NetworkID.cs new file mode 100644 index 0000000..e1a020c --- /dev/null +++ b/Assets/Scripts/Utilities/NetworkID.cs @@ -0,0 +1,18 @@ +using UnityEngine; +using Unity.Netcode; + +public class NetworkID : NetworkBehaviour +{ + // Set from enemy spawner + public int InitialID = -1; + + private NetworkVariable nID = new(); + + public int ID => nID.Value; + + public override void OnNetworkSpawn() + { + if (IsServer) + nID.Value = InitialID; + } +} diff --git a/Assets/Scripts/Utilities/NetworkID.cs.meta b/Assets/Scripts/Utilities/NetworkID.cs.meta new file mode 100644 index 0000000..0e2ef9d --- /dev/null +++ b/Assets/Scripts/Utilities/NetworkID.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e071dd818c5a905209e31c2d66ea6390 \ No newline at end of file diff --git a/Assets/Scripts/Utilities/NetworkID_Inspector.cs b/Assets/Scripts/Utilities/NetworkID_Inspector.cs new file mode 100644 index 0000000..e31c8ed --- /dev/null +++ b/Assets/Scripts/Utilities/NetworkID_Inspector.cs @@ -0,0 +1,16 @@ +#if UNITY_EDITOR +using UnityEngine; +using UnityEditor; + +[CustomEditor(typeof(NetworkID))] +public class NetworkID_Inspector : Editor +{ + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + + EditorGUILayout.LabelField($"ID: {(target as NetworkID).ID}"); + } +} + +#endif diff --git a/Assets/Scripts/Utilities/NetworkID_Inspector.cs.meta b/Assets/Scripts/Utilities/NetworkID_Inspector.cs.meta new file mode 100644 index 0000000..6398067 --- /dev/null +++ b/Assets/Scripts/Utilities/NetworkID_Inspector.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e70a0a80d88c1620c955d7bdc1efe3ee \ No newline at end of file diff --git a/Assets/Scripts/Utilities/Project.Scripts.Utilities.asmdef b/Assets/Scripts/Utilities/Project.Scripts.Utilities.asmdef index 26cf92d..2947333 100644 --- a/Assets/Scripts/Utilities/Project.Scripts.Utilities.asmdef +++ b/Assets/Scripts/Utilities/Project.Scripts.Utilities.asmdef @@ -1,3 +1,16 @@ { - "name": "Project.Scripts.Utilities" -} + "name": "Project.Scripts.Utilities", + "rootNamespace": "", + "references": [ + "GUID:1491147abca9d7d4bb7105af628b223e" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file