The following code only spawns one character controller when I’m testing this (with two builds on separate computers connected to the same server). My problem is, I want it to spawn more than one character controllers(they are already prefabs in the variables) for every player in the game. Here’s the section of the code (changed a bit to make the question make more sense) I am using to make this happen:
var WhoIsEnemy : int
var IAmPlayer : int //defines which player number you are
var HowManyReady : int //defines how many players are ready to begin the game | not important
function RandomEnemy(){
if(NetworkPeerType.Server)
{
WhoIsEnemy = Random.Range(1, (HowManyReady+2));
Debug.Log("Enemy is Player " + WhoIsEnemy);
networkView.RPC("EnemyIsF", RPCMode.All, WhoIsEnemy);
}
}
@RPC
function EnemyIsF(EnemyIs : int){
WhoIsEnemy = EnemyIs;
StartGame();
}
function StartGame(){
if(WhoIsEnemy == IAmPlayer)
{
Network.Instantiate(EnemyPrefab, transform.position, transform.rotation, 0);
}
else
{
Network.Instantiate(HumanPrefab, transform.position, transform.rotation, 0);
}
}
Update: I’ve been working on changing this code to work and it still only spawns 1 character controller that every player controls. Help please.