Here is my problem : I’m trying to make a multi player game with two teams (blue - red). When the game is launched, all the player are asked to choose a team, then they spawn on the side of the map which belong to this team. All of this stuff is working, but i can’t figure how to set a specific color (obviously red & blue) to the player prefab spawned after team selection, and how to sync them to the server. Here is a piece of code :
Spawn.js:
function OnGUI(){
if (ShowButton){
if (GUI.Button(Rect(Screen.width/2 - 60,Screen.height/2,110,50),"RED TEAM")){
ShowButton = false;
team = "rouge";
networkView.RPC("SpawnBox",RPCMode.AllBuffered,viewID, transform.position, Network.player);
}
if (GUI.Button(Rect(Screen.width/2 + 60,Screen.height/2,110,50),"BLUE TEAM")){
ShowButton = false;
team = "bleu";
networkView.RPC("SpawnBox", RPCMode.AllBuffered,viewID, transform.position, Network.player);
}
}
}
@RPC
function SpawnBox (viewID : NetworkViewID, location : Vector3, player : NetworkPlayer) {
var clone : Transform;
clone = Instantiate(playerPrefab, transform.position, Quaternion.identity) as Transform;
var nView : NetworkView;
nView = clone.GetComponent(NetworkView);
nView.viewID = viewID;
clone.transform.SendMessage("GetTeam", team, SendMessageOptions.DontRequireReceiver);
// if(clone.team == "rouge") clone.renderer.material.color = Color.red; DO NOT WORK
}
And a piece of my player script :
function Update () {
if(networkView.isMine){
renderer.material.color = myColor;
networkView.RPC("SetColor", RPCMode.AllBuffered, myColor.r, myColor.g, myColor.b);
}
}
function GetTeam(info: String){
team = info;
}
@RPC
function SetColor(r : float, g : float, b : float)
{
myColor = new Color(r, g, b);
}
It’s making me crazy being stuck with a problem like this x) Any kind of help would be appreciated a lot ^^
Thanks