78 lines
1.8 KiB
C#
78 lines
1.8 KiB
C#
using UnityEngine;
|
|
|
|
public class GameMenuVerses : MonoBehaviour
|
|
{
|
|
public GameObject PlayerPrefab;
|
|
|
|
public GameObject TinkyPrefab;
|
|
|
|
public GameObject NoFog;
|
|
|
|
public GameObject TinkySpawn;
|
|
|
|
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;
|
|
}
|
|
|
|
public void CreateTinkyPlayer()
|
|
{
|
|
connected = true;
|
|
GameObject gameObject = (GameObject)Network.Instantiate(TinkyPrefab, TinkySpawn.transform.position, TinkySpawn.transform.rotation, 1);
|
|
gameObject.GetComponent<NetworkView>().stateSynchronization = NetworkStateSynchronization.Unreliable;
|
|
Object.Instantiate(NoFog, base.transform.position, base.transform.rotation);
|
|
gameObject.transform.Find("Camera").GetComponent<Camera>().enabled = true;
|
|
gameObject.transform.Find("Camera").GetComponent<Light>().enabled = true;
|
|
base.GetComponent<Camera>().enabled = false;
|
|
}
|
|
|
|
private void OnDisconnectedFromServer()
|
|
{
|
|
connected = false;
|
|
}
|
|
|
|
private void OnPlayerDisconnected(NetworkPlayer pl)
|
|
{
|
|
Network.DestroyPlayerObjects(pl);
|
|
}
|
|
|
|
private void OnConnectedToServer()
|
|
{
|
|
CreatePlayer();
|
|
}
|
|
|
|
private void OnServerInitialized()
|
|
{
|
|
CreateTinkyPlayer();
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
if (!connected)
|
|
{
|
|
ip = GUILayout.TextField(ip);
|
|
if (GUILayout.Button("Connect as Victim"))
|
|
{
|
|
Network.Connect(ip, 5300);
|
|
}
|
|
if (GUILayout.Button("Host as Slendytubby"))
|
|
{
|
|
Network.InitializeServer(10, 5300, false);
|
|
}
|
|
}
|
|
}
|
|
}
|