Skip to content

Commit 61d3849

Browse files
committed
Refactor team and player type handling for units
Moved PlayerType enum to its own file in the Unit namespace and updated references accordingly. Improved collision logic for BasicRocket and BasicTankShell to use teamId for friendly fire checks. Updated GameScene to assign teamId to infantry units. Cleaned up unused usings and code in affected classes.
1 parent fc394d6 commit 61d3849

File tree

9 files changed

+39
-29
lines changed

9 files changed

+39
-29
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using UnityEngine;
2+
using VehicleSystem.Vehicles;
23

34
namespace AmmunitionSystem.Ammunitions
45
{
56
public class Ammunition : MonoBehaviour
67
{
78
public AmmunitionSystem.Ammunition ammunitionData;
8-
public VehicleSystem.Vehicles.Vehicle ownerVehicle;
9-
public virtual void SetRocket(Transform targetTransform)
10-
{
11-
}
9+
public Vehicle ownerVehicle;
10+
public virtual void SetRocket(Transform targetTransform) { }
1211
}
1312
}

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicBullet/BasicBullet.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using UnityEngine;
2-
using VehicleSystem.Vehicles;
3-
using BuildingPlacement.Buildings;
42

53
namespace AmmunitionSystem.Ammunitions.BasicBullet
64
{
@@ -38,6 +36,5 @@ private void OnCollisionEnter(Collision collision)
3836

3937
Destroy(gameObject);
4038
}
41-
4239
}
4340
}

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicRocket/BasicRocket.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,16 @@ private void OnCollisionEnter(Collision collision)
5858
if (ownerVehicle != null && collision.gameObject == ownerVehicle.gameObject)
5959
return;
6060

61-
if (collision.gameObject.CompareTag("Ammunition"))
61+
var unit = collision.gameObject.GetComponent<Unit.Unit>();
62+
if (unit == null)
6263
return;
6364

65+
if (unit.teamId == ownerVehicle.teamId)
66+
return;
67+
68+
Debug.Log($"Hit unit: {collision.gameObject.name}, Damage: {ammunitionData.damage}");
69+
// unit.GetComponent<HealthSystem>()?.TakeDamage(ammunitionData.damage);
70+
6471
hasExploded = true;
6572

6673
if (explosionEffectPrefab != null)
@@ -69,12 +76,6 @@ private void OnCollisionEnter(Collision collision)
6976
Destroy(explosionEffect, 2f);
7077
}
7178

72-
if (collision.gameObject.CompareTag("Enemy"))
73-
{
74-
Debug.Log($"Hit enemy: {collision.gameObject.name}, Damage: {ammunitionData.damage}");
75-
// örn: collision.gameObject.GetComponent<Health>()?.TakeDamage(ammunitionData.damage);
76-
}
77-
7879
Destroy(gameObject);
7980
}
8081
}

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicTankShell/BasicTankShell.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using UnityEngine;
2+
using BuildingPlacement.Buildings;
23

34
namespace AmmunitionSystem.Ammunitions.Ammunitions.BasicTankShell
45
{
@@ -27,9 +28,16 @@ private void OnCollisionEnter(Collision collision)
2728
if (ownerVehicle != null && collision.gameObject == ownerVehicle.gameObject)
2829
return;
2930

30-
if (collision.gameObject.CompareTag("Ammunition"))
31+
var unit = collision.gameObject.GetComponent<Unit.Unit>();
32+
if (unit == null)
3133
return;
3234

35+
if (unit.teamId == ownerVehicle.teamId)
36+
return;
37+
38+
Debug.Log($"Hit unit: {collision.gameObject.name}, Damage: {ammunitionData.damage}");
39+
// unit.GetComponent<HealthSystem>()?.TakeDamage(ammunitionData.damage);
40+
3341
hasExploded = true;
3442

3543
if (explosionEffectPrefab != null)
@@ -38,12 +46,6 @@ private void OnCollisionEnter(Collision collision)
3846
Destroy(explosionEffect, 2f);
3947
}
4048

41-
if (collision.gameObject.CompareTag("Enemy"))
42-
{
43-
Debug.Log($"Hit enemy: {collision.gameObject.name}, Damage: {ammunitionData.damage}");
44-
// örn: collision.gameObject.GetComponent<Health>()?.TakeDamage(ammunitionData.damage);
45-
}
46-
4749
Destroy(gameObject);
4850
}
4951
}

Red Strike/Assets/BuildingPlacement/Buildings/Building.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using UnityEngine;
2+
using Unit;
23

34
namespace BuildingPlacement.Buildings
45
{
@@ -36,10 +37,4 @@ private void OnCollisionEnter(Collision collision)
3637
Debug.Log($"Building {BuildingName} collided with unit: {collision.gameObject.name}");
3738
}
3839
}
39-
40-
public enum PlayerType
41-
{
42-
Red,
43-
Blue
44-
}
4540
}

Red Strike/Assets/Scenes/GameScene.unity

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,10 @@ PrefabInstance:
10561056
propertyPath: m_Name
10571057
value: Infantry
10581058
objectReference: {fileID: 0}
1059+
- target: {fileID: 3693194386570448113, guid: 652e336fe8416d44694bb7c08b2b9f16, type: 3}
1060+
propertyPath: teamId
1061+
value: 1
1062+
objectReference: {fileID: 0}
10591063
- target: {fileID: 3693194386570448113, guid: 652e336fe8416d44694bb7c08b2b9f16, type: 3}
10601064
propertyPath: targetObject
10611065
value:
@@ -1293,6 +1297,10 @@ PrefabInstance:
12931297
propertyPath: m_Name
12941298
value: Infantry (1)
12951299
objectReference: {fileID: 0}
1300+
- target: {fileID: 3693194386570448113, guid: 652e336fe8416d44694bb7c08b2b9f16, type: 3}
1301+
propertyPath: teamId
1302+
value: 2
1303+
objectReference: {fileID: 0}
12961304
- target: {fileID: 3693194386570448113, guid: 652e336fe8416d44694bb7c08b2b9f16, type: 3}
12971305
propertyPath: targetObject
12981306
value:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Unit
2+
{
3+
public enum PlayerType
4+
{
5+
Red,
6+
Blue
7+
}
8+
}

Red Strike/Assets/Unit/PlayerType.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Red Strike/Assets/Unit/Unit.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using BuildingPlacement.Buildings;
21
using UnityEngine;
32

43
namespace Unit
@@ -7,7 +6,6 @@ public class Unit : MonoBehaviour
76
{
87
[Header("Unit Info")]
98
public int teamId;
10-
119
public PlayerType playerType;
1210
}
1311
}

0 commit comments

Comments
 (0)