Update SyncVarHook.md

In the example while reading the guides it just seemed easier to put the variables at the top (as you read the OnStartServer method you see a variable and try to find what it is, but it's further down.
Easier to understand in my mind. Not sure if it's a huge issue for others
This commit is contained in:
Icezman001 2019-12-19 15:54:35 +01:00 committed by GitHub
parent f521f1b06e
commit a21ab8934b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,11 +15,6 @@ using UnityEngine.Networking;
public class PlayerController : NetworkBehaviour public class PlayerController : NetworkBehaviour
{ {
public override void OnStartServer()
{
base.OnStartServer();
playerColor = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
}
[SyncVar(hook = nameof(SetColor))] [SyncVar(hook = nameof(SetColor))]
Color playerColor = Color.black; Color playerColor = Color.black;
@ -27,6 +22,12 @@ public class PlayerController : NetworkBehaviour
// Unity makes a clone of the Material every time GetComponent<Renderer>().material is used. // Unity makes a clone of the Material every time GetComponent<Renderer>().material is used.
// Cache it here and Destroy it in OnDestroy to prevent a memory leak. // Cache it here and Destroy it in OnDestroy to prevent a memory leak.
Material cachedMaterial; Material cachedMaterial;
public override void OnStartServer()
{
base.OnStartServer();
playerColor = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
}
void SetColor(Color color) void SetColor(Color color)
{ {