- Home /
Character spawn menu bug
i have an empty object in the scene with a script that on start shows 2 buttons, each spawns a different character, however when they are pressed, they should disappear but for some reason they don't . i can't see where my mistake is, anyone see any problems with this? using UnityEngine; using System.Collections;
public class playerspawner : MonoBehaviour {
public float selectedPlayer ;
public bool isselecting;
public GameObject playerPrefab1;
public GameObject playerPrefab2;
public GameObject spawnObject;
public GameObject spawnObject2;
private bool disconnect=false;
void Start()
{
isselecting = true;
Screen.showCursor = true;
}
void Update () {
if (Input.GetKeyDown (KeyCode.Escape)) {
disconnect = !disconnect;
Screen.lockCursor = false;
Screen.showCursor = true;
}
if(isselecting!=true&&disconnect!=true)
Screen.lockCursor = true;
}
public void SpawnPlayer()
{
if (selectedPlayer == 1) {
PhotonNetwork.Instantiate (playerPrefab1.name, spawnObject.transform.position, Quaternion.identity, 0);
isselecting = false;
disconnect=false;
}
else
if (selectedPlayer == 2) {
PhotonNetwork.Instantiate (playerPrefab2.name, spawnObject2.transform.position, Quaternion.identity, 0);
isselecting =false;
disconnect=false;
}
}
void OnGUI()
{
if (isselecting != false ) {
if (GUI.Button (new Rect ( Screen.width/5, Screen.height/3,Screen.width/5, Screen.height/5), "earthbender")) {
selectedPlayer = 1;
SpawnPlayer ();
Screen.showCursor = false;
}
if (GUI.Button (new Rect ( Screen.width/5+Screen.width*2/5, Screen.height/3,Screen.width/5, Screen.height/5), "firebender")) {
selectedPlayer = 2;
SpawnPlayer ();
Screen.showCursor = false;
}
}
if(disconnect==true)
if(GUI.Button (new Rect (Screen.width/5, Screen.height/5,Screen.width/6, Screen.height/5), "Disconnect"))
{Network.Disconnect();
MasterServer.UnregisterHost();
disconnect=false;
Application.LoadLevel ("DemoWorker-Scene");
Screen.showCursor = true;
}
}
private void OnPlayerDisconnected(NetworkPlayer player) {
Debug.Log ("Clean up after player " + player);
Network.RemoveRPCs (player);
Network.DestroyPlayerObjects (player);
}
}
Comment