using UnityEngine;
using System.Collections;
public class Spawn : MonoBehaviour {
//Variables Start___________________________________
//Used to determine if the palyer needs to spawn into
//the game.
private bool justConnectedToServer = false;
//Used to determine which team the player is on.
public bool amIOnTheRedTeam = false;
public bool amIOnTheBlueTeam = false;
//Used to define the JoinTeamWindow.
private Rect joinTeamRect;
private Rect respawnRect;
private string joinTeamWindowTitle = “Scegli il Gruppo”;
private string respawnWindowTitle = “Aspetta per respawnare”;
private string respawn = “Aspetta per respawnare”;
private int joinTeamWindowWidth = 330;
private int joinTeamWindowHeight = 100;
private int joinTeamLeftIndent;
private int joinTeamTopIndent;
private int respawnLeftIndent;
private int respawnTopIndent;
private int buttonHeight = 40;
public string playerName;
private GameObject multiplayerManager;
private MultiplayerScript multiScript;
public int waitTime = 5;
//The Player prefabs are connected to these in the
//inspector
public Transform redTeamPlayer;
public Transform blueTeamPlayer;
private int redTeamGroup = 0;
private int blueTeamGroup = 1;
//Used to capture spawn points.
private GameObject redSpawnPoints;
private GameObject blueSpawnPoints;
//Used in determining whether the player is destroyed.
public bool iAmDestroyed = false;
//Used in determining if the player has spawned for the
//first time.
public bool firstSpawn = false;
//This is used in allowing the player to select a team again
//if the match has restarted.
public bool matchRestart = false;
//Variables End_____________________________________
// Use this for initialization
void Start () {
// PlayerDatabase dataScript = gameManager.GetComponent();
}
// Update is called once per frame
void Update () {
}
void OnConnectedToServer ()
{
justConnectedToServer = true;
}
void JoinTeamWindow (int windowID)
{
//Only show these two buttons when the player has just connected to
//the server or if the match has restarted. They allow the player
//choose a team and spawn into the game.
if(justConnectedToServer == true || matchRestart == true)
{
//If the player clicks on the Join Red Team button then
//assign them to the red team and spawn them into the game.
if(GUILayout.Button("Entra nel gruppo rosso", GUILayout.Height(buttonHeight)))
{
amIOnTheRedTeam = true;
justConnectedToServer = false;
matchRestart = false;
iAmDestroyed = false;
SpawnRedTeamPlayer();
firstSpawn = true;
}
//If the player clicks on the Join Blue Team button then
//assign them to the blue team and spawn them into the game.
if(GUILayout.Button("Entra nel gruppo blu", GUILayout.Height(buttonHeight)))
{
amIOnTheBlueTeam = true;
justConnectedToServer = false;
matchRestart = false;
iAmDestroyed = false;
SpawnBlueTeamPlayer();
firstSpawn = true;
}
}
}
void respawnWindow (int windowID)
{
if(iAmDestroyed == true && amIOnTheBlueTeam == true)
{
StartCoroutine(RespawnBlue());
}
if(iAmDestroyed == true && amIOnTheRedTeam == true)
{
StartCoroutine(RespawnRed());
}
}
void OnGUI()
{
//If the player has just connected to the server then draw the
//Join Team window.
if(justConnectedToServer == true || matchRestart == true
&& Network.isClient)
{
Screen.lockCursor = false;
joinTeamLeftIndent = Screen.width / 2 - joinTeamWindowWidth / 2;
joinTeamTopIndent = Screen.height / 2 - joinTeamWindowHeight / 2;
joinTeamRect = new Rect(joinTeamLeftIndent, joinTeamTopIndent,
joinTeamWindowWidth, joinTeamWindowHeight);
joinTeamRect = GUILayout.Window(0, joinTeamRect, JoinTeamWindow,
joinTeamWindowTitle);
}
if(iAmDestroyed == true)
{
joinTeamLeftIndent = Screen.width / 2 - joinTeamWindowWidth / 2;
joinTeamTopIndent = Screen.height / 2 - joinTeamWindowHeight / 2;
joinTeamRect = new Rect(joinTeamLeftIndent, joinTeamTopIndent,
joinTeamWindowWidth, joinTeamWindowHeight);
joinTeamRect = GUILayout.Window(0, joinTeamRect, respawnWindow,
joinTeamWindowTitle);
GUILayout.Box("Aspetta per respawnare");
}
}
void SpawnRedTeamPlayer ()
{
//Find all red spawn points and place a reference to them in the array
//redSpawnPoints.
iAmDestroyed = false;
redSpawnPoints = GameObject.FindGameObjectsWithTag("SpawnRossoGruppo");
//Randomly select one of those spawn points.
GameObject randomRedSpawn = redSpawnPoints[Random.Range(0, redSpawnPoints.Length)];
//Instantiate the player at the randomly selected spawn point.
Network.Instantiate(redTeamPlayer, randomRedSpawn.transform.position,
randomRedSpawn.transform.rotation, redTeamGroup);
if(firstSpawn != true)
{
playerName = "GiocatoreRosso";
}
//Access the PlayerDatabase and supply it with the team that this player
//has joined.
GameObject gameManager = GameObject.Find("GameManager");
PlayerDatabase dataScript = gameManager.GetComponent();
dataScript.joinedTeam = true;
dataScript.playerTeam = "red";
iAmDestroyed = false;
}
void SpawnBlueTeamPlayer ()
{
//Find all blue spawn points and place a reference to them in the array
//blueSpawnPoints.
blueSpawnPoints = GameObject.FindGameObjectsWithTag("SpawnBluGruppo");
//Randomly select one of those spawn points.
GameObject randomBlueSpawn = blueSpawnPoints[Random.Range(0, blueSpawnPoints.Length)];
//Instantiate the player at the randomly selected spawn point.
Network.Instantiate(blueTeamPlayer, randomBlueSpawn.transform.position,
randomBlueSpawn.transform.rotation, blueTeamGroup);
if(firstSpawn != true)
{
playerName = "PlayerBlue";
}
//Access the PlayerDatabase and supply it with the team that this player
//has joined.
GameObject gameManager = GameObject.Find("GameManager");
PlayerDatabase dataScript = gameManager.GetComponent();
dataScript.joinedTeam = true;
dataScript.playerTeam = "blue";
iAmDestroyed = false;
}
IEnumerator RespawnBlue ()
{
yield return new WaitForSeconds (waitTime);
iAmDestroyed = false;
SpawnBlueTeamPlayer();
}
IEnumerator RespawnRed ()
{
yield return new WaitForSeconds (waitTime);
iAmDestroyed = false;
SpawnRedTeamPlayer();
}
Unity say me that the last parsign is wrong, why?