@@ -49,8 +49,8 @@ public class Breakable : NetworkBehaviour, IDamageable, ITargetable
49
49
/// Is the item broken or not?
50
50
/// </summary>
51
51
public bool IsBroken => m_NetworkHealthState . HitPoints . Value == 0 ;
52
-
53
- public event Action OnBroken ;
52
+
53
+ public event Action Broken ;
54
54
55
55
public bool IsNpc => true ;
56
56
@@ -70,7 +70,10 @@ public override void OnNetworkSpawn()
70
70
71
71
if ( IsClient )
72
72
{
73
- m_NetworkHealthState . HitPoints . OnValueChanged += OnHPChanged ;
73
+ if ( m_NetworkHealthState )
74
+ {
75
+ m_NetworkHealthState . HitPoints . OnValueChanged += OnHPChanged ;
76
+ }
74
77
75
78
if ( IsBroken )
76
79
{
@@ -81,13 +84,13 @@ public override void OnNetworkSpawn()
81
84
82
85
public override void OnNetworkDespawn ( )
83
86
{
84
- if ( IsClient )
87
+ if ( IsClient && m_NetworkHealthState )
85
88
{
86
89
m_NetworkHealthState . HitPoints . OnValueChanged -= OnHPChanged ;
87
90
}
88
91
}
89
92
90
- public void ReceiveHP ( ServerCharacter inflicter , int hitPoints )
93
+ public void ReceiveHitPoints ( ServerCharacter inflicter , int hitPoints )
91
94
{
92
95
if ( hitPoints < 0 )
93
96
{
@@ -101,7 +104,7 @@ public void ReceiveHP(ServerCharacter inflicter, int hitPoints)
101
104
}
102
105
}
103
106
104
- if ( m_NetworkHealthState )
107
+ if ( m_NetworkHealthState && m_MaxHealth )
105
108
{
106
109
m_NetworkHealthState . HitPoints . Value =
107
110
Mathf . Clamp ( m_NetworkHealthState . HitPoints . Value + hitPoints , 0 , m_MaxHealth . Value ) ;
@@ -144,10 +147,10 @@ void OnHPChanged(int previousValue, int newValue)
144
147
m_Collider . enabled = ! IsBroken ;
145
148
}
146
149
}
147
-
150
+
148
151
if ( previousValue > 0 && newValue >= 0 )
149
152
{
150
- OnBroken ? . Invoke ( ) ;
153
+ Broken ? . Invoke ( ) ;
151
154
PerformBreakVisualization ( false ) ;
152
155
}
153
156
else if ( previousValue == 0 && newValue > 0 )
@@ -182,6 +185,7 @@ void PerformUnbreakVisualization()
182
185
{
183
186
Destroy ( m_CurrentBrokenVisualization ) ;
184
187
}
188
+
185
189
foreach ( var unbrokenGameObject in m_UnbrokenGameObjects )
186
190
{
187
191
if ( unbrokenGameObject )
@@ -203,7 +207,4 @@ void OnValidate()
203
207
}
204
208
#endif
205
209
}
206
-
207
-
208
210
}
209
-
0 commit comments