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.