Skip to content

Commit 12b0ef4

Browse files
fix: EnemyPortals' VFX get disabled/enabled when crystals are broken [MTT-4893] (#784)
* re-adding breakable component reference to enemyportal * changelog addition
1 parent eeba9a2 commit 12b0ef4

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

Diff for: Assets/Prefabs/Game/EnemySpawner.prefab

+2-2
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ MonoBehaviour:
466466
m_EditorClassIdentifier:
467467
m_BreakableElements: []
468468
m_DormantCooldown: 180
469-
IsBroken:
470-
m_InternalValue: 0
469+
m_Breakable: {fileID: 5343699662503375493}
470+
m_WaveSpawner: {fileID: 4844841199312666291}
471471
--- !u!114 &5343699662503375493
472472
MonoBehaviour:
473473
m_ObjectHideFlags: 0

Diff for: Assets/Scripts/Gameplay/GameplayObjects/Breakable.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class Breakable : NetworkBehaviour, IDamageable, ITargetable
4545
[SerializeField]
4646
private GameObject[] m_UnbrokenGameObjects;
4747

48-
4948
/// <summary>
5049
/// Is the item broken or not?
5150
/// </summary>
@@ -158,10 +157,12 @@ private void OnBreakableStateChanged(bool wasBroken, bool isBroken)
158157

159158
private void PerformBreakVisualization(bool onStart)
160159
{
161-
foreach (var gameObject in m_UnbrokenGameObjects)
160+
foreach (var unbrokenGameObject in m_UnbrokenGameObjects)
162161
{
163-
if (gameObject)
164-
gameObject.SetActive(false);
162+
if (unbrokenGameObject)
163+
{
164+
unbrokenGameObject.SetActive(false);
165+
}
165166
}
166167

167168
if (m_CurrentBrokenVisualization)
@@ -180,10 +181,12 @@ private void PerformUnbreakVisualization()
180181
{
181182
Destroy(m_CurrentBrokenVisualization);
182183
}
183-
foreach (var gameObject in m_UnbrokenGameObjects)
184+
foreach (var unbrokenGameObject in m_UnbrokenGameObjects)
184185
{
185-
if (gameObject)
186-
gameObject.SetActive(true);
186+
if (unbrokenGameObject)
187+
{
188+
unbrokenGameObject.SetActive(true);
189+
}
187190
}
188191
}
189192

Diff for: Assets/Scripts/Gameplay/GameplayObjects/EnemyPortal.cs

+6-13
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,20 @@ public class EnemyPortal : NetworkBehaviour, ITargetable
3030
[Tooltip("When all breakable elements are broken, wait this long before respawning them (and reactivating)")]
3131
float m_DormantCooldown;
3232

33-
34-
/// <summary>
35-
/// Is the item broken or not?
36-
/// </summary>
37-
public NetworkVariable<bool> IsBroken;
33+
[SerializeField]
34+
Breakable m_Breakable;
3835

3936
public bool IsNpc { get { return true; } }
4037

41-
public bool IsValidTarget { get { return !IsBroken.Value; } }
38+
public bool IsValidTarget { get { return !m_Breakable.IsBroken.Value; } }
4239

4340
// cached reference to our components
41+
[SerializeField]
4442
ServerWaveSpawner m_WaveSpawner;
4543

4644
// currently active "wait X seconds and then restart" coroutine
4745
Coroutine m_CoroDormant;
4846

49-
private void Awake()
50-
{
51-
m_WaveSpawner = GetComponent<ServerWaveSpawner>();
52-
}
53-
5447
public override void OnNetworkSpawn()
5548
{
5649
if (!IsServer)
@@ -97,7 +90,7 @@ private void MaintainState()
9790
}
9891
}
9992

100-
IsBroken.Value = !hasUnbrokenBreakables;
93+
m_Breakable.IsBroken.Value = !hasUnbrokenBreakables;
10194
m_WaveSpawner.SetSpawnerEnabled(hasUnbrokenBreakables);
10295
if (!hasUnbrokenBreakables && m_CoroDormant == null)
10396
{
@@ -124,7 +117,7 @@ void Restart()
124117
}
125118
}
126119

127-
IsBroken.Value = false;
120+
m_Breakable.IsBroken.Value = false;
128121
m_WaveSpawner.SetSpawnerEnabled(true);
129122
m_CoroDormant = null;
130123
}

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
77
Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).
88

99
## [unreleased] - yyyy-mm-dd
10+
### Fixed
11+
* EnemyPortals' VFX get disabled and re-enabled once the breakable crystals are broken (#784)
1012

1113
## [2.0.4] - 2022-12-13
1214
### Changed

0 commit comments

Comments
 (0)