mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix(Reward): Simplified and better comments
This commit is contained in:
parent
1f9faf2044
commit
2b2e4131a5
@ -24,34 +24,29 @@ protected override void OnValidate()
|
|||||||
[ServerCallback]
|
[ServerCallback]
|
||||||
void OnTriggerEnter(Collider other)
|
void OnTriggerEnter(Collider other)
|
||||||
{
|
{
|
||||||
if (other.gameObject.CompareTag("Player"))
|
// Set up physics layers to prevent this from being called by non-players
|
||||||
ClaimPrize(other.gameObject);
|
// and eliminate the need for a tag check here.
|
||||||
}
|
if (!other.CompareTag("Player")) return;
|
||||||
|
|
||||||
[ServerCallback]
|
// This is a fast switch to prevent two players claiming the prize in a bang-bang close contest for it.
|
||||||
void ClaimPrize(GameObject player)
|
// First to trigger turns it off, pending the object being destroyed a few frames later.
|
||||||
{
|
if (!available)
|
||||||
if (available)
|
return;
|
||||||
{
|
else
|
||||||
// This is a fast switch to prevent two players claiming the prize in a bang-bang close contest for it.
|
|
||||||
// First hit turns it off, pending the object being destroyed a few frames later.
|
|
||||||
available = false;
|
available = false;
|
||||||
|
|
||||||
Color32 color = randomColor.color;
|
// Calculate the points from the color...lighter scores higher as the average approaches 255
|
||||||
|
// UnityEngine.Color RGB values are byte 0 to 255
|
||||||
|
uint points = (uint)((randomColor.color.r + randomColor.color.g + randomColor.color.b) / 3);
|
||||||
|
|
||||||
// calculate the points from the color ... lighter scores higher as the average approaches 255
|
// award the points via SyncVar on Player's PlayerScore
|
||||||
// UnityEngine.Color RGB values are float fractions of 255
|
other.GetComponent<PlayerScore>().score += points;
|
||||||
uint points = (uint)(((color.r) + (color.g) + (color.b)) / 3);
|
|
||||||
|
|
||||||
// award the points via SyncVar on the PlayerController
|
// spawn a replacement
|
||||||
player.GetComponent<PlayerScore>().score += points;
|
Spawner.SpawnReward();
|
||||||
|
|
||||||
// spawn a replacement
|
// destroy this one
|
||||||
Spawner.SpawnReward();
|
NetworkServer.Destroy(gameObject);
|
||||||
|
|
||||||
// destroy this one
|
|
||||||
NetworkServer.Destroy(gameObject);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user