Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created July 20, 2017 23:44
Show Gist options
  • Save unity3dcollege/5da8db425d83c0d0299d50bb2401c394 to your computer and use it in GitHub Desktop.
Save unity3dcollege/5da8db425d83c0d0299d50bb2401c394 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.Networking;
public class PlayerColor : NetworkBehaviour
{
[SyncVar]
public Color color = Color.white;
private void Update()
{
GetComponent<SpriteRenderer>().color = color;
if (isLocalPlayer && Input.GetButtonDown("Fire1"))
PickRandomColor();
}
private void PickRandomColor()
{
var newcolor = new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), 1f);
CmdSetColorOnServer(newcolor);
}
[Command]
public void CmdSetColorOnServer(Color newColor)
{
color = newColor;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment