Skip to content

Commit

Permalink
fix: Rewards default position and enabled checks
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGadget1024 committed Dec 21, 2024
1 parent 726d49d commit ecc3c6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Assets/Mirror/Examples/MultipleAdditiveScenes/Scripts/Reward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Common.RandomColor>();
Expand All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions Assets/Mirror/Examples/Room/Scripts/Reward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Common.RandomColor>();
Expand All @@ -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;
Expand Down

0 comments on commit ecc3c6e

Please sign in to comment.