Hi guys I have a problem with my script.I made a script that if my player loads a level then The public bool will become true and make a gui button but i have no idea why when i put this script it automaticly put the public to true.Please help.thanks
public Player MyPlayer;
public GameObject SpawnPlayer;
public bool MatchStarted;
//public bool MatchLoaded;
// Use this for initialization
void Start () {
Instance = this;
DontDestroyOnLoad(gameObject);
}
// Update is called once per frame
void Update () {
PlayerName = PlayerPrefs.GetString("PlayerName");
}
public void StartServer(string ServerName, int MaxPlayers)
{
Network.InitializeSecurity();
Network.InitializeServer (MaxPlayers, 25565, true);
MasterServer.RegisterHost("Tut", ServerName, "");
Debug.Log("Started Server");
}
void OnPlayerConnected(NetworkPlayer id)
{
//networkView.RPC ("Server_PlayerJoined", RPCMode.Server, PlayerName, id);
foreach (Player pl in PlayerList)
{
networkView.RPC("Client_PlayerJoined",id,pl.PlayerName, pl.OnlinePlayer);
}
}
void OnServerInitialized()
{
Server_PlayerJoined (PlayerName, Network.player);
}
void OnConnectedToServer()
{
networkView.RPC ("Server_PlayerJoined", RPCMode.Server, PlayerName, Network.player);
}
void OnPlayerDisconnected(NetworkPlayer id)
{
networkView.RPC ("RemovePlayer", RPCMode.All, id);
Network.RemoveRPCs(id);
}
void OnDisconnectedFromServer(NetworkDisconnection info)
{
PlayerList.Clear ();
}
[RPC]
public void Server_PlayerJoined(string Username,NetworkPlayer id)
{
networkView.RPC("Client_PlayerJoined", RPCMode.All,PlayerName, id);
}
[RPC]
public void Client_PlayerJoined(string Username,NetworkPlayer id)
{
Player temp = new Player();
temp.PlayerName = Username;
temp.OnlinePlayer = id;
PlayerList.Add(temp);
if (Network.player == id)
{
MyPlayer = temp;
Network.Instantiate(SpawnPlayer,Vector3.zero,Quaternion.identity,0);
}
}
[RPC]
public void RemovePlayer(NetworkPlayer id)
{
Player temp = new Player ();
foreach(Player pl in PlayerList)
{
if(pl.OnlinePlayer == id)
{
temp = pl;
}
}
if(temp !=null)
{
PlayerList.Remove (temp);
}
}
[RPC]
public void LoadLevel()
{
Application.LoadLevel (1);
MatchStarted = true;
}
void OnGUI()
{
if(MatchStarted = true)
{
if(GUI.Button(new Rect(0,0,50,20),"Spawn"))
{
MyPlayer.Manager.networkView.RPC("Spawn",RPCMode.All);
}
}
}
[System.Serializable]
public class Player{
public string PlayerName;
public NetworkPlayer OnlinePlayer;
public float Health = 100;
public Character Manager;
}
}