From ecc3c6e23fa999eabc9253d73d5a15c2966f13b1 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Sat, 21 Dec 2024 11:20:09 -0500 Subject: [PATCH] fix: Rewards default position and enabled checks --- .../MultipleAdditiveScenes/Scripts/Reward.cs | 12 ++++++++++++ Assets/Mirror/Examples/Room/Scripts/Reward.cs | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Reward.cs b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Reward.cs index 079d9fc9ed..9644f25788 100644 --- a/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Reward.cs +++ b/Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Reward.cs @@ -15,7 +15,16 @@ public class Reward : NetworkBehaviour protected override void OnValidate() { + if (Application.isPlaying) return; + base.OnValidate(); + Reset(); + } + + void Reset() + { + // Default position out of reach + transform.position = new Vector3(0, -1000, 0); if (randomColor == null) randomColor = GetComponent(); @@ -29,6 +38,9 @@ public override void OnStartServer() [ServerCallback] void OnTriggerEnter(Collider other) { + // Don't process collisions when it's in the pool + if (!gameObject.activeSelf) return; + // Set up physics layers to prevent this from being called by non-players // and eliminate the need for a tag check here. if (!other.CompareTag("Player")) return; diff --git a/Assets/Mirror/Examples/Room/Scripts/Reward.cs b/Assets/Mirror/Examples/Room/Scripts/Reward.cs index 5d01516fe1..564b059b3f 100644 --- a/Assets/Mirror/Examples/Room/Scripts/Reward.cs +++ b/Assets/Mirror/Examples/Room/Scripts/Reward.cs @@ -15,7 +15,16 @@ public class Reward : NetworkBehaviour protected override void OnValidate() { + if (Application.isPlaying) return; + base.OnValidate(); + Reset(); + } + + void Reset() + { + // Default position out of reach + transform.position = new Vector3(0, -1000, 0); if (randomColor == null) randomColor = GetComponent(); @@ -29,6 +38,9 @@ public override void OnStartServer() [ServerCallback] void OnTriggerEnter(Collider other) { + // Don't process collisions when it's in the pool + if (!gameObject.activeSelf) return; + // Set up physics layers to prevent this from being called by non-players // and eliminate the need for a tag check here. if (!other.CompareTag("Player")) return;