Files
Slendytubbies-V2-Beta/V2Beta/Assets/Scripts/Assembly-CSharp/GameMenusingleplayer.cs
T
2026-05-24 12:14:04 +02:00

68 lines
1.4 KiB
C#

using UnityEngine;
public class GameMenusingleplayer : MonoBehaviour
{
public GameObject PlayerPrefab;
public GameObject TinkyPrefab;
private string ip = "127.0.0.1";
private bool connected;
public void Awake()
{
Application.runInBackground = true;
}
public void CreatePlayer()
{
connected = true;
GameObject gameObject = (GameObject)Network.Instantiate(PlayerPrefab, base.transform.position, base.transform.rotation, 1);
gameObject.GetComponent<NetworkView>().stateSynchronization = NetworkStateSynchronization.Unreliable;
gameObject.transform.Find("Camera").GetComponent<Camera>().enabled = true;
base.GetComponent<Camera>().enabled = false;
}
private void OnDisconnectedFromServer()
{
connected = false;
}
private void OnPlayerDisconnected(NetworkPlayer pl)
{
Network.DestroyPlayerObjects(pl);
}
private void OnServerInitialized()
{
CreatePlayer();
}
private void OnGUI()
{
if (!connected && GUILayout.Button("Start"))
{
Network.InitializeServer(10, 5300, false);
}
}
private void Start()
{
Network.InitializeServer(10, 5300, false);
DisableAllBeginGameObjects();
}
private void DisableAllBeginGameObjects()
{
GameObject[] allObjects = FindObjectsOfType(typeof(GameObject)) as GameObject[];
foreach (GameObject obj in allObjects)
{
if (obj.name == "Begin game")
{
obj.SetActive(false);
}
}
}
}