Last active
June 13, 2019 20:09
-
-
Save SocketWeaver/23777453a9c4e6150977fc888d37f2d1 to your computer and use it in GitHub Desktop.
Set the WinnerId SyncProperty to the player who completed the laps first
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void OnTriggerEnter(Collider other) | |
{ | |
GameObject go = other.gameObject; | |
NetworkID networkID = go.GetComponent<NetworkID>(); | |
// check if the player is the local player | |
if (networkID.IsMine) | |
{ | |
lap_ = lap_ + 1; | |
guiManager.SetLapRecord(lap_, lapsToWin); | |
if (lap_ == lapsToWin) | |
{ | |
Debug.Log("Winner!!"); | |
string winnerId = remotePropertyAgent.GetPropertyWithName(WIINER_ID).GetStringValue(); | |
Debug.Log("OnTriggerEnter winnerID " + winnerId); | |
// if winnerId is empty, local player is the winner | |
// If the winner did not leave the game and finished the laps again, the player should still be the winner | |
if (string.IsNullOrEmpty(winnerId) || winnerId.Equals(NetworkClient.Instance.PlayerId)) | |
{ | |
remotePropertyAgent.Modify(WIINER_ID, NetworkClient.Instance.PlayerId); | |
guiManager.SetMainText("1st"); | |
} | |
else | |
{ | |
guiManager.SetMainText("2nd"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment