Ok, so I found a solution… however, it was not “pretty simple” or straight forward, so if anyone happens to know a better way for dooing this, please let me know.
Here is my current solution. Let me know if it is not complete, and does not make sense, it is ripped out from my code, that is a “bit” too complex to post here for a simple answer.
I start out on the server.
public NetworkView ncoNetworkView; //The NetworkControlObject, wich is activef on the client.
public void OnPlayerConnected (NetworkPlayer newPlayer)
{
ncoNetworkView.RPC("GetNetworkPlayer", RPCMode.AllBuffered, newPlayer);
}
Then in the NetworkControlObjectScript (attached to the networkview) I do the following
//This is to make sure that we remember the Networkplayer that is used on the server.
[RPC]
public void GetNetworkPlayer (NetworkPlayer player)
{
owner = player;
if (player == Network.player) {
guiOn = true;
}
}
void OnGUI ()
{
if (guiOn) {
GUILayout.BeginArea (new Rect (Screen.width / 2 - 125, Screen.height - 85, 250, 80));
GUILayout.Box ("This is the size of the unitarray: " + unitList.Count);
if (GUILayout.Button ("Join Team 1")) {
spawnView.RPC ("spawnMethod", RPCMode.Server, 1, owner);
guiOn = false;
}
if (GUILayout.Button ("Join Team 2")) {
spawnView.RPC ("spawnMethod", RPCMode.Server, 2, owner);
guiOn = false;
}
GUILayout.EndArea ();
}
}
Back at the server again, I initiate the unit, and set the networkplayer to be owner, making sure that the player has control over the units that were just spawned. (And this is cut down quite a bit, since I have more things going on when spawning units, this is not interesting for the current example.)
[RPC]
public void spawnMethod(int teamNumber, NetworkPlayer clientPlayer)
{
Spawnplayer (clientPlayer, teamNumber);
}
public void Spawnplayer (NetworkPlayer newPlayer, int team)
{
int playerNumber = int.Parse (newPlayer.ToString ());
//This spawnins units for the player.
for (int i = 1; i <= numberOfUnits; i++) {
GameObject tempUnit = (GameObject)Network.Instantiate (units, this.transform.position * (i * 0.1f), Quaternion.identity, playerNumber);
unitList.Add (tempUnit);
Transform modelPart = tempUnit.transform.root.Find ("Model");
NetworkView newUnitsNetworkview = modelPart.networkView;
newUnitsNetworkview.RPC ("SetPlayer", RPCMode.AllBuffered, newPlayer);
}
}