using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class CapController : NetworkBehaviour
{
public bool blueTeam = false;
public bool redTeam = false;
private float redcaptureperc = 0;
private float bluecaptureperc = 0;
public GameObject flagRed;
public GameObject flagBlue;
public GameObject flagNeutral;
public Rect capturebox = new Rect(10, 10, 300, 25);
void Start()
{
flagNeutral.GetComponent<MeshRenderer>().enabled = true;
}
[Server]
public void ServerUpdate()
{
if (redcaptureperc != 100)
{
flagRed.GetComponent<MeshRenderer>().enabled = true;
flagBlue.GetComponent<MeshRenderer>().enabled = false;
flagNeutral.GetComponent<MeshRenderer>().enabled = false;
}
if (bluecaptureperc != 100)
{
flagRed.GetComponent<MeshRenderer>().enabled = false;
flagBlue.GetComponent<MeshRenderer>().enabled = true;
flagNeutral.GetComponent<MeshRenderer>().enabled = false;
}
if ((redcaptureperc >= 50 && bluecaptureperc >= 51) || (redcaptureperc >= 51 && bluecaptureperc >= 50))
{
flagRed.GetComponent<MeshRenderer>().enabled = false;
flagBlue.GetComponent<MeshRenderer>().enabled = false;
flagNeutral.GetComponent<MeshRenderer>().enabled = true;
}
}
[ClientRpc]
public void RpcUpdate()
{
if (redcaptureperc != 100)
{
flagRed.GetComponent<MeshRenderer>().enabled = true;
flagBlue.GetComponent<MeshRenderer>().enabled = false;
flagNeutral.GetComponent<MeshRenderer>().enabled = false;
}
if (bluecaptureperc != 100)
{
flagRed.GetComponent<MeshRenderer>().enabled = false;
flagBlue.GetComponent<MeshRenderer>().enabled = true;
flagNeutral.GetComponent<MeshRenderer>().enabled = false;
}
if ((redcaptureperc <= 50 && bluecaptureperc <= 51) || (redcaptureperc >= 51 && bluecaptureperc >= 50))
{
flagRed.GetComponent<MeshRenderer>().enabled = false;
flagBlue.GetComponent<MeshRenderer>().enabled = false;
flagNeutral.GetComponent<MeshRenderer>().enabled = true;
}
}
void Update()
{
if (blueTeam == true)
{
bluecaptureperc += Time.deltaTime * 20;
redcaptureperc -= Time.deltaTime * 20;
}
if (redTeam == true)
{
redcaptureperc += Time.deltaTime * 20;
bluecaptureperc -= Time.deltaTime * 20;
}
if (redTeam == true && blueTeam == true)
{
redcaptureperc = redcaptureperc;
bluecaptureperc = bluecaptureperc;
}
if (redcaptureperc >= 100)
{
redcaptureperc = 100;
flagRed.GetComponent<MeshRenderer>().enabled = true;
flagBlue.GetComponent<MeshRenderer>().enabled = false;
flagNeutral.GetComponent<MeshRenderer>().enabled = false;
}
if (bluecaptureperc >= 100)
{
bluecaptureperc = 100;
flagRed.GetComponent<MeshRenderer>().enabled = false;
flagBlue.GetComponent<MeshRenderer>().enabled = true;
flagNeutral.GetComponent<MeshRenderer>().enabled = false;
}
if ((redcaptureperc <= 50 && bluecaptureperc <= 51) || (redcaptureperc >= 51 && bluecaptureperc >= 50))
{
flagRed.GetComponent<MeshRenderer>().enabled = false;
flagBlue.GetComponent<MeshRenderer>().enabled = false;
flagNeutral.GetComponent<MeshRenderer>().enabled = true;
}
if (redcaptureperc <= 0)
{
redcaptureperc = 0;
}
if (bluecaptureperc <= 0)
{
bluecaptureperc = 0;
}
}
void OnGUI()
{
GUI.Box(capturebox, "Red Cap " + ((int)redcaptureperc).ToString() + " Blue Cap " + ((int)bluecaptureperc).ToString());
}
}
My problem is the flags meshrenderer isnt sent to all the clients. I.E: Player tagged red captures the flag after some seconds flag turns red, but for the other client its still the color as flagNeutral. I’ve been struggling for a couple of days and been trying to understand something from the unity manual but no luck. Please help.