File tree Expand file tree Collapse file tree 7 files changed +51
-5
lines changed
AmmunitionSystem/Ammunitions/Ammunitions
BuildingPlacement/Buildings Expand file tree Collapse file tree 7 files changed +51
-5
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,7 @@ private void OnCollisionEnter(Collision collision)
3131 if ( unit . teamId == ownerVehicle . teamId )
3232 return ;
3333
34- Debug . Log ( $ "Hit unit: { collision . gameObject . name } , Damage: { ammunitionData . damage } ") ;
35- // unit.GetComponent<HealthSystem>()?.TakeDamage(ammunitionData.damage);
34+ unit . TakeDamage ( ammunitionData . damage ) ;
3635
3736 Destroy ( gameObject ) ;
3837 }
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ private void OnCollisionEnter(Collision collision)
6666 return ;
6767
6868 Debug . Log ( $ "Hit unit: { collision . gameObject . name } , Damage: { ammunitionData . damage } ") ;
69- // unit.GetComponent<HealthSystem>()? .TakeDamage(ammunitionData.damage);
69+ unit . TakeDamage ( ammunitionData . damage ) ;
7070
7171 hasExploded = true ;
7272
Original file line number Diff line number Diff line change 11using UnityEngine ;
2- using BuildingPlacement . Buildings ;
32
43namespace AmmunitionSystem . Ammunitions . Ammunitions . BasicTankShell
54{
@@ -36,7 +35,7 @@ private void OnCollisionEnter(Collision collision)
3635 return ;
3736
3837 Debug . Log ( $ "Hit unit: { collision . gameObject . name } , Damage: { ammunitionData . damage } ") ;
39- // unit.GetComponent<HealthSystem>()? .TakeDamage(ammunitionData.damage);
38+ unit . TakeDamage ( ammunitionData . damage ) ;
4039
4140 hasExploded = true ;
4241
Original file line number Diff line number Diff line change @@ -25,6 +25,20 @@ private void Start()
2525 health = maxHealth ;
2626 }
2727
28+ public override void TakeDamage ( float damage )
29+ {
30+ health -= damage ;
31+ health = Mathf . Max ( 0 , health ) ;
32+
33+ Debug . Log ( $ "Building { BuildingName } took { damage } damage. Remaining health: { health } ") ;
34+
35+ if ( health <= 0 )
36+ {
37+ Debug . Log ( $ "Building { BuildingName } destroyed.") ;
38+ Destroy ( gameObject ) ;
39+ }
40+ }
41+
2842 private void OnCollisionEnter ( Collision collision )
2943 {
3044 var unit = collision . gameObject . GetComponent < Unit . Unit > ( ) ;
Original file line number Diff line number Diff line change @@ -635,6 +635,7 @@ GameObject:
635635 - component : {fileID: 460729959}
636636 - component : {fileID: 460729964}
637637 - component : {fileID: 460729963}
638+ - component : {fileID: 460729965}
638639 m_Layer : 6
639640 m_Name : Sphere
640641 m_TagString : Enemy
@@ -762,6 +763,20 @@ MonoBehaviour:
762763 precomputeOutline : 0
763764 bakeKeys : []
764765 bakeValues : []
766+ --- !u!114 &460729965
767+ MonoBehaviour :
768+ m_ObjectHideFlags : 0
769+ m_CorrespondingSourceObject : {fileID: 0}
770+ m_PrefabInstance : {fileID: 0}
771+ m_PrefabAsset : {fileID: 0}
772+ m_GameObject : {fileID: 460729958}
773+ m_Enabled : 1
774+ m_EditorHideFlags : 0
775+ m_Script : {fileID: 11500000, guid: bcb4f7460ecc9104b9932edfb5089ede, type: 3}
776+ m_Name :
777+ m_EditorClassIdentifier :
778+ teamId : 5
779+ playerType : 0
765780--- !u!1 &483664587 stripped
766781GameObject :
767782 m_CorrespondingSourceObject : {fileID: 224654450759790032, guid: 652e336fe8416d44694bb7c08b2b9f16, type: 3}
Original file line number Diff line number Diff line change @@ -7,5 +7,10 @@ public class Unit : MonoBehaviour
77 [ Header ( "Unit Info" ) ]
88 public int teamId ;
99 public PlayerType playerType ;
10+
11+ public virtual void TakeDamage ( float damage )
12+ {
13+ // Implement damage logic here
14+ }
1015 }
1116}
Original file line number Diff line number Diff line change @@ -310,5 +310,19 @@ protected virtual void ReloadRocketAmmunition()
310310 currentAmmunition_rocket = rocketAmmunitionSettings . maxAmmunition ;
311311 }
312312 }
313+
314+ public override void TakeDamage ( float damage )
315+ {
316+ health -= damage ;
317+ health = Mathf . Max ( 0 , health ) ;
318+
319+ Debug . Log ( $ "Vehicle { vehicleData . vehicleName } took { damage } damage. Remaining health: { health } ") ;
320+
321+ if ( health <= 0 )
322+ {
323+ Debug . Log ( $ "Vehicle { vehicleData . vehicleName } destroyed.") ;
324+ Destroy ( gameObject ) ;
325+ }
326+ }
313327 }
314328}
You can’t perform that action at this time.
0 commit comments