Exemple #1
0
        public void StartGame(string scene)
        {
            LevelManager.Instance.InitObjects();
            DestroyImmediate(Connection.GetComponent <ClientConnection>());
            DestroyImmediate(Connection.GetComponent <ServerConnection>());
            DestroyImmediate(Connection.GetComponent <SingleplayerConnection>());

            //SingleplayerConnection conn = serverObject.AddComponent<SingleplayerConnection>();
            //conn.Init();
            ushort port = 27015;
            string host = GameObject.Find("TargetHostField").GetComponent <InputField>().text;

            string[] parts = host.Split(':');
            if (parts.Length > 1)
            {
                host = parts[0];
                port = ushort.Parse(parts[1]);
            }
            ClientConnection conn = Connection.AddComponent <ClientConnection>();

            try
            {
                conn.AttemptConnect(host, port, string.Empty);
            }
            catch (Exception)
            {
                DestroyImmediate(conn);
            }
            DontDestroyOnLoad(Connection);
        }