Last active
August 29, 2015 14:13
-
-
Save BrentFarris/36c5b46d495348746aa2 to your computer and use it in GitHub Desktop.
Forge Networking Sample: Autostart Scene
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using BeardedManStudios.Network; | |
public class StartGame : MonoBehaviour | |
{ | |
public string host = "127.0.0.1"; // IP address | |
public ushort port = 15937; // Port number | |
public Networking.TransportationProtocolType protocolType = Networking.TransportationProtocolType.UDP; // Communication protocol | |
public int playerCount = 31; // Maximum player count -- excluding this server | |
public string sceneName = "Game"; // Scene to load | |
private NetWorker socket = null; | |
private bool ready = false; | |
#if UNITY_WINRT && !UNITY_EDITOR | |
private bool isWinRT = true; | |
#else | |
private bool isWinRT = false; | |
#endif | |
public void Start() | |
{ | |
Networking.InitializeFirewallCheck(port); | |
} | |
public void StartServer() | |
{ | |
socket = Networking.Host((ushort)port, protocolType, playerCount, false, isWinRT); | |
} | |
public void StartClient() | |
{ | |
socket = Networking.Connect(host, (ushort)port, protocolType, isWinRT); | |
} | |
private void Update() | |
{ | |
if (socket != null && socket.Connected) | |
{ | |
Networking.SetPrimarySocket(socket); | |
Application.LoadLevel(sceneName); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment