diff --git a/Assets/Code/Scripts/C#/Managers/EnemyShipManager.cs b/Assets/Code/Scripts/C#/Managers/EnemyShipManager.cs index 52af856c..f7abca0e 100644 --- a/Assets/Code/Scripts/C#/Managers/EnemyShipManager.cs +++ b/Assets/Code/Scripts/C#/Managers/EnemyShipManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using UnityEngine; using System.Linq; +using UnityEngine.Events; using Random = UnityEngine.Random; public class EnemyShipManager : MonoBehaviour @@ -10,14 +11,14 @@ public class EnemyShipManager : MonoBehaviour [SerializeField] GameObject[] _enemyShipPrefabs; [SerializeField] int _maxEnemies = 1; [SerializeField] float _firstSpawnInterval = 10f, _spawnInterval = 30f; - [SerializeField] float _minSpawnRange = 500f, _maxSpawnRange = 1000f; + [SerializeField] float _minSpawnRange = 500f, _maxSpawnRange = 2000f; - List _enemyShips; + List _enemyShips; float _spawnDelay; Transform _transform; int MaxEnemies { get; set; } float SpawnInterval { get; set; } - int ActiveEnemies => _enemyShips.Count(e => e.gameObject.activeSelf); + int ActiveEnemies => _enemyShips.Count(e => e.activeSelf); bool CanSpawnEnemyShip { @@ -39,15 +40,10 @@ void Awake() void OnEnable() { - _enemyShips = new List(); + _enemyShips = new List(); _spawnDelay = _firstSpawnInterval; } - private void Start() - { - GameManager.Instance.GameStateChanged += OnGameStateChanged; - } - void Update() { if (CanSpawnEnemyShip) @@ -58,12 +54,10 @@ void Update() void SpawnEnemyShip() { - if (GameManager.Instance.GameState == GameState.GameOver) return; var spawnPosition = Random.insideUnitSphere * Random.Range(_minSpawnRange, _maxSpawnRange); var enemy = Instantiate(RandomPrefab, _transform); - EnemyShipController enemyShipController = enemy.GetComponent(); - enemyShipController.ShipDestroyed.AddListener(OnShipDestroyed); - _enemyShips.Add(enemyShipController); + enemy.GetComponent().ShipDestroyed.AddListener(OnShipDestroyed); + _enemyShips.Add(enemy); enemy.transform.position = spawnPosition; _spawnDelay = SpawnInterval; } @@ -73,30 +67,14 @@ void OnShipDestroyed(int id) for (var i = 0; i < _enemyShips.Count; ++i) { var ship = _enemyShips[i]; - if (ship.gameObject.GetInstanceID() != id) continue; - + if (ship.GetInstanceID() != id) continue; _enemyShips.RemoveAt(i); ship.GetComponent().ShipDestroyed.RemoveListener(OnShipDestroyed); Destroy(ship.gameObject); - - if (_enemyShips.Count == 0) // Check if all enemy ships are destroyed - { - GameManager.Instance.PlayerWon(); - } return; } - } - - private void OnGameStateChanged(GameState gameState) - { - if (gameState != GameState.GameOver) return; - while (_enemyShips.Any()) - { - var ship = _enemyShips[0]; - ship.ShipDestroyed.RemoveListener(OnShipDestroyed); - ship.gameObject.SetActive(false); - _enemyShips.Remove(ship); - } + + ++MaxEnemies; } } diff --git a/Assets/Code/Scripts/C#/ShipControls/AIShipWeaponControls.cs b/Assets/Code/Scripts/C#/ShipControls/AIShipWeaponControls.cs index 76f74316..6259d220 100644 --- a/Assets/Code/Scripts/C#/ShipControls/AIShipWeaponControls.cs +++ b/Assets/Code/Scripts/C#/ShipControls/AIShipWeaponControls.cs @@ -4,7 +4,6 @@ public class AIShipWeaponControls : WeaponControlsBase { - public override bool PrimaryFired => _firePrimary; public override bool SecondaryFired => _fireSecondary; diff --git a/Assets/Code/Scripts/C#/ShipControls/EnemyShipController.cs b/Assets/Code/Scripts/C#/ShipControls/EnemyShipController.cs index 9cbf759b..97955d39 100644 --- a/Assets/Code/Scripts/C#/ShipControls/EnemyShipController.cs +++ b/Assets/Code/Scripts/C#/ShipControls/EnemyShipController.cs @@ -28,7 +28,7 @@ enum EnemyShipState Transform _target; public UnityEvent ShipDestroyed = new UnityEvent(); - + #region Public data for debugging public string ShipState => _state.ToString(); @@ -43,13 +43,12 @@ public string DistanceToTarget { distance = $"{Vector3.Distance(_target.position, _transform.position):F2}"; } - return distance; } } public string HealthLevel => $"{_damageHandler.Health}/{_damageHandler.MaxHealth}"; - + #endregion bool InAttackRange => Vector3.Distance(PlayerShip.transform.position, _transform.position) <= _attackRange; @@ -80,11 +79,6 @@ public override void Update() EnemyShipState state = GetNextState(); SetState(state); base.Update(); - - if (_state == EnemyShipState.Patrol || _state == EnemyShipState.Attack) - { - Debug.Log($"{_transform.name} is {_state} at distance {DistanceToTarget} to target {_target.name}"); - } } EnemyShipState GetNextState() @@ -95,23 +89,21 @@ EnemyShipState GetNextState() EnemyShipState.Attack => Attack(), EnemyShipState.Reposition => Reposition(), EnemyShipState.Retreat => Retreat(), - _ => EnemyShipState.None + _ => EnemyShipState.None }; return newState; } EnemyShipState Patrol() { - if (ShouldRetreat) return EnemyShipState.Retreat; if (InAttackRange) return EnemyShipState.Attack; if (ReachedPatrolTarget) { _target.position = Random.insideUnitSphere * _patrolRange; } - + return EnemyShipState.Patrol; - } EnemyShipState Attack() @@ -136,9 +128,6 @@ EnemyShipState Retreat() void SetState(EnemyShipState state) { if (_state == state) return; - - Debug.Log($"State Change: {_transform.name} from {_state} to {state} at position {_transform.position}"); - _state = state; switch (state) { @@ -148,10 +137,7 @@ void SetState(EnemyShipState state) _target = new GameObject("Patrol Target").transform; _target.position = Random.insideUnitSphere * _patrolRange; _aiShipMovementControls.SetTarget(_target); - - Debug.Log("Patrol Target Set: " + _target.position); } - break; case EnemyShipState.Attack: if (_target) @@ -162,9 +148,6 @@ void SetState(EnemyShipState state) _target = PlayerShip.transform; _aiShipMovementControls.SetTarget(_target); SetWeaponsTarget(_target, _attackRange, _targetMask); - - Debug.Log($"{_transform.name} has the player in attack range at distance {Vector3.Distance(PlayerShip.transform.position, _transform.position)}"); - Debug.Log("Attacking Player Ship: " + _target.name); break; case EnemyShipState.Reposition: _aiShipMovementControls.SetTarget(_target = GetRepositionTarget()); @@ -173,7 +156,6 @@ void SetState(EnemyShipState state) case EnemyShipState.Retreat: _aiShipMovementControls.SetTarget(_target = GetRetreatTarget()); SetWeaponsTarget(null, 0, 0); - Debug.Log($"{_transform.name} is retreating due to low health at position {_transform.position}"); break; } } diff --git a/Assets/Level/Prefabs/Ship/EnemyShip.prefab b/Assets/Level/Prefabs/Ship/EnemyShip.prefab index 28d5262b..613b1cbe 100644 --- a/Assets/Level/Prefabs/Ship/EnemyShip.prefab +++ b/Assets/Level/Prefabs/Ship/EnemyShip.prefab @@ -4896,10 +4896,10 @@ GameObject: - component: {fileID: 3270137435280878765} - component: {fileID: 3830503309714405520} - component: {fileID: 1670868690125025214} - - component: {fileID: 3273414822229855833} - component: {fileID: 6386423043768917572} - component: {fileID: 9101981412856683548} - component: {fileID: -3452145308914408502} + - component: {fileID: 4868072809919850034} m_Layer: 9 m_Name: EnemyShip m_TagString: Untagged @@ -4916,8 +4916,8 @@ Transform: m_GameObject: {fileID: 4672143511779763784} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 2.1972837, y: 2.1972837, z: 2.1972837} + m_LocalPosition: {x: 0, y: 0, z: -500} + m_LocalScale: {x: 4.340276, y: 4.340276, z: 4.340276} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 2094068067535200792} @@ -4979,7 +4979,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4672143511779763784} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 904d618a25d78c048b458334ca7b65b6, type: 3} m_Name: @@ -4995,7 +4995,7 @@ MonoBehaviour: - {fileID: 3918258386833207449} - {fileID: 6479749987046297272} _cockpitAnimationControls: {fileID: 0} ---- !u!114 &3273414822229855833 +--- !u!114 &6386423043768917572 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -5004,32 +5004,12 @@ MonoBehaviour: m_GameObject: {fileID: 4672143511779763784} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7540eac5b4c7f6343a125827f3a3d109, type: 3} + m_Script: {fileID: 11500000, guid: 11b902442feaa2043b9431e9f55336c0, type: 3} m_Name: m_EditorClassIdentifier: - _shield: {fileID: 3439661430968737132, guid: e0db6bf163f6de54a8e3483047ff2eaf, type: 3} - _movementControls: {fileID: 954444670952009420} - _weaponControls: {fileID: 3495697174989805755} - _shipData: {fileID: 11400000, guid: d0626ff996fb64840a629d98e93b538a, type: 2} - _engines: - - {fileID: 1965405259545024898} - - {fileID: 8919091462575576586} - _blasters: - - {fileID: 3918258386833207449} - - {fileID: 6479749987046297272} - _cockpitAnimationControls: {fileID: 0} - _patrolRange: 2000 - _attackRange: 1000 - _targetMask: - serializedVersion: 2 - m_Bits: 4544 - _playerMask: - serializedVersion: 2 - m_Bits: 320 - ShipDestroyed: - m_PersistentCalls: - m_Calls: [] ---- !u!114 &6386423043768917572 + _explosionPrefab: {fileID: 1076125496127895026, guid: 0415aeb6da821704ba3ce11ab72e936d, + type: 3} +--- !u!114 &9101981412856683548 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -5038,12 +5018,11 @@ MonoBehaviour: m_GameObject: {fileID: 4672143511779763784} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 11b902442feaa2043b9431e9f55336c0, type: 3} + m_Script: {fileID: 11500000, guid: 058a328f10df29a40a593556ac8b3957, type: 3} m_Name: m_EditorClassIdentifier: - _explosionPrefab: {fileID: 1076125496127895026, guid: 0415aeb6da821704ba3ce11ab72e936d, - type: 3} ---- !u!114 &9101981412856683548 + _points: 1000 +--- !u!114 &-3452145308914408502 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -5052,11 +5031,10 @@ MonoBehaviour: m_GameObject: {fileID: 4672143511779763784} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 058a328f10df29a40a593556ac8b3957, type: 3} + m_Script: {fileID: 11500000, guid: 7d7724e04d9b36845b6ad420c22cb0a5, type: 3} m_Name: m_EditorClassIdentifier: - _points: 1000 ---- !u!114 &-3452145308914408502 +--- !u!114 &4868072809919850034 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -5065,9 +5043,31 @@ MonoBehaviour: m_GameObject: {fileID: 4672143511779763784} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7d7724e04d9b36845b6ad420c22cb0a5, type: 3} + m_Script: {fileID: 11500000, guid: 7540eac5b4c7f6343a125827f3a3d109, type: 3} m_Name: m_EditorClassIdentifier: + _shield: {fileID: 3255451610787643643} + _movementControls: {fileID: 954444670952009420} + _weaponControls: {fileID: 3495697174989805755} + _shipData: {fileID: 11400000, guid: d0626ff996fb64840a629d98e93b538a, type: 2} + _engines: + - {fileID: 1965405259545024898} + - {fileID: 8919091462575576586} + _blasters: + - {fileID: 3918258386833207449} + - {fileID: 6479749987046297272} + _cockpitAnimationControls: {fileID: 0} + _patrolRange: 2000 + _attackRange: 1000 + _targetMask: + serializedVersion: 2 + m_Bits: 4544 + _playerMask: + serializedVersion: 2 + m_Bits: 64 + ShipDestroyed: + m_PersistentCalls: + m_Calls: [] --- !u!1 &4727912295285831519 GameObject: m_ObjectHideFlags: 0 @@ -10429,6 +10429,11 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 3270137435280878765} m_Modifications: + - target: {fileID: -1643793514769958191, guid: e0db6bf163f6de54a8e3483047ff2eaf, + type: 3} + propertyPath: m_CollisionDetection + value: 2 + objectReference: {fileID: 0} - target: {fileID: 1621680531775960475, guid: e0db6bf163f6de54a8e3483047ff2eaf, type: 3} propertyPath: m_Name @@ -10500,6 +10505,18 @@ Transform: type: 3} m_PrefabInstance: {fileID: 185085349280112023} m_PrefabAsset: {fileID: 0} +--- !u!114 &3255451610787643643 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 3439661430968737132, guid: e0db6bf163f6de54a8e3483047ff2eaf, + type: 3} + m_PrefabInstance: {fileID: 185085349280112023} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2c28b3aeaf63c254b9d9298153ba2048, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!114 &5062410429266757221 stripped MonoBehaviour: m_CorrespondingSourceObject: {fileID: -4264691883905262606, guid: e0db6bf163f6de54a8e3483047ff2eaf, @@ -10560,6 +10577,21 @@ PrefabInstance: propertyPath: m_SizeDelta.y value: 1080 objectReference: {fileID: 0} + - target: {fileID: 164837289807977997, guid: 50a4080d0115d0f4e9e29dbaa3a79c67, + type: 3} + propertyPath: m_LocalScale.x + value: 0.0039505837 + objectReference: {fileID: 0} + - target: {fileID: 164837289807977997, guid: 50a4080d0115d0f4e9e29dbaa3a79c67, + type: 3} + propertyPath: m_LocalScale.y + value: 0.002962937 + objectReference: {fileID: 0} + - target: {fileID: 164837289807977997, guid: 50a4080d0115d0f4e9e29dbaa3a79c67, + type: 3} + propertyPath: m_LocalScale.z + value: 0.0019752919 + objectReference: {fileID: 0} - target: {fileID: 164837289807977997, guid: 50a4080d0115d0f4e9e29dbaa3a79c67, type: 3} propertyPath: m_LocalPosition.x @@ -10603,7 +10635,7 @@ PrefabInstance: - target: {fileID: 164837289807977997, guid: 50a4080d0115d0f4e9e29dbaa3a79c67, type: 3} propertyPath: m_AnchoredPosition.y - value: 3.1108 + value: 3.64 objectReference: {fileID: 0} - target: {fileID: 164837289807977997, guid: 50a4080d0115d0f4e9e29dbaa3a79c67, type: 3} @@ -10717,12 +10749,17 @@ PrefabInstance: - target: {fileID: 6338935799411866526, guid: 2adc4e042a59c0c41a1dbf0a8b09150b, type: 3} propertyPath: m_LocalScale.x - value: 0.002 + value: 0.003956089 objectReference: {fileID: 0} - target: {fileID: 6338935799411866526, guid: 2adc4e042a59c0c41a1dbf0a8b09150b, type: 3} propertyPath: m_LocalScale.y - value: 0.0015 + value: 0.0029670664 + objectReference: {fileID: 0} + - target: {fileID: 6338935799411866526, guid: 2adc4e042a59c0c41a1dbf0a8b09150b, + type: 3} + propertyPath: m_LocalScale.z + value: 0.0019780444 objectReference: {fileID: 0} - target: {fileID: 6338935799411866526, guid: 2adc4e042a59c0c41a1dbf0a8b09150b, type: 3} @@ -10909,8 +10946,7 @@ PrefabInstance: type: 3} propertyPath: _target value: - objectReference: {fileID: 6124476701410091073, guid: e6f3b60206ee26a46b6a1ca0a1f2d189, - type: 3} + objectReference: {fileID: 0} - target: {fileID: 8987843823871055711, guid: 1577e5dd8241208448dca18d6f6cc369, type: 3} propertyPath: _layerMask.m_Bits diff --git a/Assets/Level/Prefabs/Ship/PlayerShip.prefab b/Assets/Level/Prefabs/Ship/PlayerShip.prefab index f1d8d8eb..8138e145 100644 --- a/Assets/Level/Prefabs/Ship/PlayerShip.prefab +++ b/Assets/Level/Prefabs/Ship/PlayerShip.prefab @@ -1623,7 +1623,7 @@ GameObject: - component: {fileID: 3391272593369453790} - component: {fileID: 4240281340487047836} - component: {fileID: 6890315079427253565} - - component: {fileID: 2322893884689107370} + - component: {fileID: 8580203568821505049} m_Layer: 6 m_Name: PlayerShip m_TagString: Player @@ -6511,7 +6511,7 @@ ParticleSystemRenderer: m_MeshWeighting2: 1 m_MeshWeighting3: 1 m_MaskInteraction: 0 ---- !u!114 &2322893884689107370 +--- !u!114 &8580203568821505049 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -6528,7 +6528,7 @@ MonoBehaviour: _layerMask: serializedVersion: 2 m_Bits: 512 - _radarRange: 1000 + _radarRange: 500 _lockOnRange: 1000 _lockOnRadius: 15 _maxTargets: 200