Spawning player based on choice

Hi Everyone

I’ve posted this kind of question before but my code wasn’t formatted properly and I didn’t explain myself well enough.

What I need is to be able to have a player spawn based on the team color that the player picks in my Main Menu. Now I have set up two test game objects that hold the Tags “RedSpawnPoint” and “BlueSpawnPoint”. Now I have the decisions that the player makes in one script and the loading of the game in another script.

I’ll post the two functions that I need help with and hopefully someone can help me.

//This is the decision the player has to make

public function showLobby(){
var players = “”;
var currentPlayerCount : int =0;
for (var playerInstance : PlayerInfo in playerList) {
players=playerInstance.username+"
"+players;
currentPlayerCount++;
}

GUI.BeginGroup (Rect (Screen.width/2-300, Screen.height/2-200, 600, 500));
GUI.Box (Rect (0,0,400,200), "Game lobby");


var pProtected="no";
if(serverPasswordProtected){
	pProtected="yes";
}
GUI.color = Color.red;
GUI.Label (Rect (110,20,150,20), "Password protected: ");
GUI.Label (Rect (250,20,100,100), pProtected);
GUI.color = Color.blue;
GUI.Label (Rect (110,40,150,20), "Server title: ");
GUI.Label (Rect (250,40,100,100), serverTitle);

GUI.color = Color.red;
GUI.Label (Rect (110, 60, 150, 20), "GameType Selected: ");
GUI.Label (Rect (250, 60, 100, 100), serverGameTypeSelected);

if (serverGameTypeSelected != "DM")
{
GUI.color = Color.blue;
    GUI.Label (Rect (110, 120, 150, 20), "Choose Team: ");
    //chooseTeamInt = GUI.Toolbar ( Rect (250, 120, 100, 20), chooseTeamInt, chooseTeamNames);
    
    PlayerPrefs.SetString("playerTeam","");
    GUI.color = Color.red;
    GUI.Button(Rect(200,120,80,20),"Red");
	PlayerPrefs.SetString("playerTeam", "");
	GUI.color = Color.blue;
    GUI.Button(Rect(280,120,80,20),"Blue");
    
  
    }

GUI.color = Color.red;
GUI.Label (Rect (110,80,150,20), "Players: ");
GUI.Label (Rect (250,80,100,100), currentPlayerCount+"/"+serverMaxPlayers);
GUI.color = Color.blue;
GUI.Label (Rect (110,100,150,20), "Current players: ");
GUI.Label (Rect (250,100,100,300), players);
GUI.color = Color.red;
GUI.Label (Rect (250, 330, 150, 20), "Choose Player");
chosenPlayerInt = GUI.Toolbar (Rect(0, 350, 600, 30), chosenPlayerInt, chosenPlayerNames);

Then there is the loading code

public function OnNetworkLoadedLevel()

{
if(GameLobby == “Red”)
{
var redSpawnPoints = GameObject.FindGameObjectsWithTag(“RedSpawnPoints”);
Debug.Log("Spawns: " + redSpawnPoints);

var redSpawnPoint :Transform = redSpawnPoints[UnityEngine.Random.Range(0, redSpawnPoints.Length)].transform;
var newTrans = Network.Instantiate(playerPref, redSpawnPoint.position, redSpawnPoint.rotation, 0) as Transform;

}
else if(GameLobby == “Blue”)
{
var blueSpawnPoints = GameObject.FindGameObjectsWithTag(“BlueSpawnPoints”);
Debug.Log("Spawns: " + blueSpawnPoints);

var blueSpawnPoint :Transform = blueSpawnPoints[UnityEngine.Random.Range(0, blueSpawnPoints.Length)].transform;
var newTrans2 = Network.Instantiate(playerPref, blueSpawnPoint.position, blueSpawnPoint.rotation, 0) as Transform;
}

}

I hope someone can help me out this is a huge issue I’m having.

Well, simply thought, you could have 4 transform positions, in a transform array.

I would guess the player is choosing before the starting of the scene.

Then each index is a color choice and you can use the start function to apply the proper transform

var pos: Vector3[];


function Start(){
pos[0]=Vector3(x1,y1,z1);
pos[1]=Vector3(x2,y2,z2);
pos[2]=Vector3(x3,y3,z3);
pos[3]=Vector3(x4,y4,z4);

switch (choice){
     case "red":
       transform.position=pos[0];
       break;
     case"blue":
       transform.position=pos[1];
       break;
      //and so on}
    }

Then when the playing scene is on the player is on the color base position.
Helping?

EDIT: I added the array declaration, I changed the name for pos as naming an array array is not convenient. Then in the Start, which happens before the scene starts, you need to give the positions you want the players to start from.