i made a capture the point script but im trying to convert it so it would work in multiplayer and im having trouble because nothing is working
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());
}
}
when a player enters a trigger area the player tagged red or blue start capturing the area and flag will change color to red or blue depending what teams percentage is 100. but the flags color change isnt sent to all the clients that are playing.
I have added a network identity to the flags and made it local player only and its still not working. WHAT AM I DOING WRONG? networking is so annoying.