Created
July 20, 2017 23:44
-
-
Save unity3dcollege/5da8db425d83c0d0299d50bb2401c394 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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