@@ -49,8 +49,8 @@ public class Breakable : NetworkBehaviour, IDamageable, ITargetable
4949 /// Is the item broken or not?
5050 /// </summary>
5151 public bool IsBroken => m_NetworkHealthState . HitPoints . Value == 0 ;
52-
53- public event Action OnBroken ;
52+
53+ public event Action Broken ;
5454
5555 public bool IsNpc => true ;
5656
@@ -70,7 +70,10 @@ public override void OnNetworkSpawn()
7070
7171 if ( IsClient )
7272 {
73- m_NetworkHealthState . HitPoints . OnValueChanged += OnHPChanged ;
73+ if ( m_NetworkHealthState )
74+ {
75+ m_NetworkHealthState . HitPoints . OnValueChanged += OnHPChanged ;
76+ }
7477
7578 if ( IsBroken )
7679 {
@@ -81,13 +84,13 @@ public override void OnNetworkSpawn()
8184
8285 public override void OnNetworkDespawn ( )
8386 {
84- if ( IsClient )
87+ if ( IsClient && m_NetworkHealthState )
8588 {
8689 m_NetworkHealthState . HitPoints . OnValueChanged -= OnHPChanged ;
8790 }
8891 }
8992
90- public void ReceiveHP ( ServerCharacter inflicter , int hitPoints )
93+ public void ReceiveHitPoints ( ServerCharacter inflicter , int hitPoints )
9194 {
9295 if ( hitPoints < 0 )
9396 {
@@ -101,7 +104,7 @@ public void ReceiveHP(ServerCharacter inflicter, int hitPoints)
101104 }
102105 }
103106
104- if ( m_NetworkHealthState )
107+ if ( m_NetworkHealthState && m_MaxHealth )
105108 {
106109 m_NetworkHealthState . HitPoints . Value =
107110 Mathf . Clamp ( m_NetworkHealthState . HitPoints . Value + hitPoints , 0 , m_MaxHealth . Value ) ;
@@ -144,10 +147,10 @@ void OnHPChanged(int previousValue, int newValue)
144147 m_Collider . enabled = ! IsBroken ;
145148 }
146149 }
147-
150+
148151 if ( previousValue > 0 && newValue >= 0 )
149152 {
150- OnBroken ? . Invoke ( ) ;
153+ Broken ? . Invoke ( ) ;
151154 PerformBreakVisualization ( false ) ;
152155 }
153156 else if ( previousValue == 0 && newValue > 0 )
@@ -182,6 +185,7 @@ void PerformUnbreakVisualization()
182185 {
183186 Destroy ( m_CurrentBrokenVisualization ) ;
184187 }
188+
185189 foreach ( var unbrokenGameObject in m_UnbrokenGameObjects )
186190 {
187191 if ( unbrokenGameObject )
@@ -203,7 +207,4 @@ void OnValidate()
203207 }
204208#endif
205209 }
206-
207-
208210}
209-
0 commit comments