Dear Community,
i hope someone out there is able to assist me in solving this issue:
I have a Mutliplayersetup (from GTGD Series on Youtube).
When i connect to the game two buttons are represented (blue and red team as in the Tutorial)
I want to hide one of those buttons when one Player joins this Team.
So i setup a Count and when the button is clicked the count is ++
When i run a server outside the Editor from a build and a game in teh editor, then all bools and my count are shown correctly in the Editor.
But when i do it the other way and run the server in the editor and connect from outside with a gamebuild, then the buttons still appear. When i set the count to 1 manually the buttons are gone so the script is working.
This still happens when we connect via Hamachi, the buttons stay until i set it manually to 1.
All other functions work and there are some bools too so why this one does not work?
Here is the code:
using UnityEngine;
using System.Collections;
/// <summary>
/// This script is attached to the SpawnManager and it allows
/// the player to spawn into the multiplayer game.
/// </summary>
public class SpawnScript : MonoBehaviour {
//Variables Start___________________________________
//Used to determine if the palyer needs to spawn into
//the game.
private bool justConnectedToServer = false;
public int redCount = 0;
public int blueCount = 0;
//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 string joinTeamWindowTitle = "Team Selection";
private int joinTeamWindowWidth = 330;
private int joinTeamWindowHeight = 100;
private int joinTeamLeftIndent;
private int joinTeamTopIndent;
private int buttonHeight = 40;
//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;
//Variables End_____________________________________
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
void OnConnectedToServer ()
{
justConnectedToServer = true;
}
void JoinTeamWindow (int windowID)
{
if(redCount < 1)
{
//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("Join Red Team", GUILayout.Height(buttonHeight)))
{
redCount++;
amIOnTheRedTeam = true;
justConnectedToServer = false;
SpawnRedTeamPlayer();
}
}
if(blueCount < 1)
{
//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("Join Blue Team", GUILayout.Height(buttonHeight)))
{
blueCount++;
amIOnTheBlueTeam = true;
justConnectedToServer = false;
SpawnBlueTeamPlayer();
}
}
}
void OnGUI()
{
//If the player has just connected to the server then draw the
//Join Team window.
if(justConnectedToServer == 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, JoinTeamWindow,
joinTeamWindowTitle);
}
}