I have a cube in my scene. I want to change its color and I wanna server and all players to see it in this color. I have attached script on the cube:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class Cube : NetworkBehaviour
{
[SyncVar(hook = "OnColorChanged")]
public Color myColor;
void OnColorChanged(Color value)
{
GetComponent<Renderer>().material.color = myColor;
Debug.Log(value + "," + myColor);
}
void Update()
{
Debug.Log(myColor);
}
}
I run GameObject.FindWithTag("cube").GetComponent<Cube>().myColor = Color.red;
this in my host script when I want to change the color of the cube, but nothing happens.