Enemies now only spawning on server

This commit is contained in:
BOTAlex 2024-02-28 19:27:24 +01:00
parent f203b6d710
commit a5e033535e
10 changed files with 317 additions and 19 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cd051c0e424080e48b1aa01ceadcb2d3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,115 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &7065654593080984807
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8461174584827419671}
- component: {fileID: -5104676121986888125}
- component: {fileID: 5063378671874793948}
- component: {fileID: -2259174063119120971}
- component: {fileID: -9003688753200063495}
m_Layer: 0
m_Name: EnemyBase
m_TagString: Enemy
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8461174584827419671
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7065654593080984807}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &-5104676121986888125
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: 1fdfc885f1a69704b893825cf9e616ba, type: 3}
m_Name:
m_EditorClassIdentifier:
bloodRegen: 0
regen: 1000
onlyCallZeroHealthOnce: 1
maxHealth: 100
damageTickDelay: 0.25
OnHealthZero:
m_PersistentCalls:
m_Calls: []
OnHealthChange:
m_PersistentCalls:
m_Calls: []
minThreshold: 1
squezeDamageScalor: 1
--- !u!195 &5063378671874793948
NavMeshAgent:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7065654593080984807}
m_Enabled: 1
m_AgentTypeID: 0
m_Radius: 0.5
m_Speed: 3.5
m_Acceleration: 8
avoidancePriority: 50
m_AngularSpeed: 120
m_StoppingDistance: 0
m_AutoTraverseOffMeshLink: 1
m_AutoBraking: 1
m_AutoRepath: 1
m_Height: 2
m_BaseOffset: 0
m_WalkableMask: 4294967295
m_ObstacleAvoidanceType: 4
--- !u!114 &-2259174063119120971
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: 6a3ffc4a3af9e0243ac9ee0c995bb82f, type: 3}
m_Name:
m_EditorClassIdentifier:
targets: []
ropeDistCheck: 1
ropeCheckMask:
serializedVersion: 2
m_Bits: 0
--- !u!114 &-9003688753200063495
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: c66441ada081b6c4c841000e83cc2b7a, type: 3}
m_Name:
m_EditorClassIdentifier:
flipTrans: {fileID: 0}
body: {fileID: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: cfacc720818aabb4e9217dd1ae770886
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: af319b5b6381dc148a533528428d1b9a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a26e54bc4c4c85a4cbf60f0b079afd5b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,121 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &2771943719147783420
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 7065654593080984807, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
propertyPath: m_Name
value: EnemyV1
objectReference: {fileID: 0}
- target: {fileID: 8461174584827419671, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8461174584827419671, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8461174584827419671, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8461174584827419671, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8461174584827419671, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8461174584827419671, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8461174584827419671, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8461174584827419671, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8461174584827419671, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8461174584827419671, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 7065654593080984807, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
insertIndex: 1
addedObject: {fileID: -4044306820387615481}
m_SourcePrefab: {fileID: 100100000, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
--- !u!1 &4934207185621008411 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 7065654593080984807, guid: cfacc720818aabb4e9217dd1ae770886, type: 3}
m_PrefabInstance: {fileID: 2771943719147783420}
m_PrefabAsset: {fileID: 0}
--- !u!212 &-4044306820387615481
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4934207185621008411}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 6ec94328ea22672429ca48d1aa458679, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1.43, y: 2.19}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 854e7815477416848ba19ede927d8601
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -3680,6 +3680,9 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 809911508645467208, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3}
insertIndex: -1
addedObject: {fileID: 1683288374126251330}
- targetCorrespondingSourceObject: {fileID: 809911508645467208, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3}
insertIndex: -1
addedObject: {fileID: 1683288374126251336}
m_SourcePrefab: {fileID: 100100000, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3}
--- !u!4 &1683288374126251322 stripped
Transform:
@ -3711,6 +3714,30 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Players: []
--- !u!114 &1683288374126251336
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1566837117}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8a592fac78e06964b863b67047a446a1, type: 3}
m_Name:
m_EditorClassIdentifier:
Wave: 0
difficulty: 1
difficultyIncreasePerWave: 3
WaveTime: 20
enemyDifficulties: []
SpawnRadius: 22.6
NumEnemies: 6
players: []
initialSpawnDelay: 5
SpawnCenter: {fileID: 5796191506433166635}
timer: 0
enemyList: []
--- !u!1001 &4158834148864819266
PrefabInstance:
m_ObjectHideFlags: 0
@ -3722,7 +3749,7 @@ PrefabInstance:
- target: {fileID: 1656765803503857110, guid: 48e0e53445d42474895d37a321c39d1c, type: 3}
propertyPath: spawner
value:
objectReference: {fileID: 5796191506433166634}
objectReference: {fileID: 0}
- target: {fileID: 2404937059918327841, guid: 48e0e53445d42474895d37a321c39d1c, type: 3}
propertyPath: m_AnchorMax.y
value: 1
@ -3974,7 +4001,8 @@ PrefabInstance:
propertyPath: m_Name
value: CameraRig
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 3603265075407754381, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
@ -3982,17 +4010,11 @@ PrefabInstance:
insertIndex: -1
addedObject: {fileID: 213238742}
m_SourcePrefab: {fileID: 100100000, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
--- !u!114 &5796191506433166634 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 3603265075407754381, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
--- !u!4 &5796191506433166635 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 8946450710138871461, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
m_PrefabInstance: {fileID: 5796191506433166633}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8a592fac78e06964b863b67047a446a1, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &7693964683212020007
PrefabInstance:
m_ObjectHideFlags: 0

View File

@ -5,12 +5,13 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Unity.Mathematics;
using Unity.Netcode;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UIElements;
public class EnemySpawner : MonoBehaviour
public class EnemySpawner : NetworkBehaviour
{
// Shared
public int Wave = 0;
@ -24,11 +25,12 @@ public class EnemySpawner : MonoBehaviour
[SerializeField] private int NumEnemies = 6;
[SerializeField] public GameObject[] players;
[SerializeField] private float initialSpawnDelay = 5;
[Space(10)]
[SerializeField] private Transform SpawnCenter;
// local
private bool nextWaveRequested = false;
public float timer = 0f;
private Camera mainCam;
private GameObject SpawnedEnenmyHolder;
[SerializeField] private List<EnemyPrefabInfo> enemyList;
@ -50,7 +52,6 @@ public class EnemySpawner : MonoBehaviour
private void Start()
{
mainCam = Camera.main;
SpawnedEnenmyHolder = new GameObject("SpawnedEnenmyHolder");
for (int i = 0; i < 6; i++)
@ -60,6 +61,7 @@ public class EnemySpawner : MonoBehaviour
timer = WaveTime - initialSpawnDelay;
if (!IsClient) // If server then start spawning
StartSpawning();
}
@ -70,8 +72,6 @@ public class EnemySpawner : MonoBehaviour
if (timer > WaveTime || nextWaveRequested)
{
Task.Factory.StartNew(() => { Task.Delay(100); timer = 0; });
SpawnWave(difficulty);
Wave++;
@ -129,6 +129,7 @@ public class EnemySpawner : MonoBehaviour
}
}
// Centrum is SpawnCenter
public Vector3 GetRandomPointOnCircle(float radius)
{
Vector3 point;
@ -137,7 +138,7 @@ public class EnemySpawner : MonoBehaviour
float angle = UnityEngine.Random.Range(0f, 360f);
float radians = Mathf.Deg2Rad * angle;
Vector3 position = transform.position;
Vector3 position = SpawnCenter.position;
float x = position.x + radius * Mathf.Cos(radians);
float y = position.y + radius * Mathf.Sin(radians);

View File

@ -6,7 +6,8 @@
"GUID:2ea4a18a75f268848b43865100892489",
"GUID:055e16077a1232f4780a04598b3bfe00",
"GUID:1031dfc67c8f1a645b71d679ac3bf7db",
"GUID:0ba5c175a7b2c8345a4e996560a9d0ab"
"GUID:0ba5c175a7b2c8345a4e996560a9d0ab",
"GUID:1491147abca9d7d4bb7105af628b223e"
],
"includePlatforms": [],
"excludePlatforms": [],