- Home /
Having problems with Network.Instantiate
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.
Answer by TrollHachem · Sep 11, 2014 at 03:12 PM
In the editor , does it instantiate 1 Object , or 2 objects but both players control only 1 if it's 2 Objects ,then you forgot to deactivate controls for the Player that is not "Yours" , you have to check if it's yours using networkView.isMine , if it's not yours simply deactivate the control scripts and the camera.