Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Dedicated server and connection

Discussion in 'Multiplayer' started by Resilo, Jun 7, 2017.

  1. Resilo

    Resilo

    Joined:
    Dec 8, 2016
    Posts:
    139
    So i have a networking script the hosting portion is to only be used for the server and not players in general so it is removed in the connecting client versions


    So assume first of all i have all the settings correct within my own computer/router etc and i have a lot of knowledge as far as networking goes

    The way my current script is set up should someone else be able to connect simple by clicking the connect button? as far as i can see this makes sense but i am not well versed in the unity networking API's











    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class networkmenu : NetworkBehaviour
    7. {
    8.  
    9.     public int portnumber = 7777;
    10.     public string serveripaddress = "[insert public ip address here]";
    11.  
    12.  
    13.  
    14.     public void hostgame()
    15.     {
    16.         NetworkManager.singleton.networkPort = portnumber;
    17.         NetworkLobbyManager.singleton.StartServer();
    18.         GameObject.Find("Manager").GetComponent<Manager>().Mainmenu.SetActive(false);
    19.     }
    20.  
    21.     public void joingame()
    22.     {
    23.         NetworkManager.singleton.networkPort = portnumber;
    24.         NetworkManager.singleton.networkAddress = serveripaddress;
    25.         NetworkLobbyManager.singleton.StartClient();
    26.         GameObject.Find("Manager").GetComponent<Manager>().Mainmenu.SetActive(false);
    27.  
    28.     }
    29.  
    30.     public void DisconnectClient()
    31.     {
    32.         NetworkLobbyManager.singleton.StopClient();
    33.         GameObject.Find("Manager").GetComponent<Manager>().Mainmenu.SetActive(true); ;
    34.  
    35.     }
    36.  
    37.  
    38.  
    39.  
    40.  
    41.     // Use this for initialization
    42.     void Start()
    43.     {
    44.  
    45.     }
    46.  
    47.     // Update is called once per frame
    48.     void Update()
    49.     {
    50.  
    51.     }
    52. }
    53.