Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

UNET Join game without Hamachi

Discussion in 'UNet' started by awaterpistol, Sep 14, 2015.

  1. awaterpistol

    awaterpistol

    Joined:
    Sep 3, 2015
    Posts:
    25
    Hi All,

    I was wondering if you'd be able to help me set up my game to allow friends to join. At the moment, I have a basic character controller and capsule as the player that moves around. He can shoot projectiles at another player, and kill him.

    This all works on localhost and when I am playing with myself. However, when I try to change the localhost name to my IP address, no one can connect to me; I can't even connect to myself - none of the buttons work anymore.

    I've portforwarded all the correct ports. My friends can connect to a similar game on the old Networking so I know the ports are open.

    Any idea how to resolve this?
     
    Last edited: Sep 14, 2015
  2. TheDreamEXE

    TheDreamEXE

    Joined:
    May 14, 2015
    Posts:
    60
    Can you take a screenshot of your editor with your NetworkManager GUI?
     
  3. awaterpistol

    awaterpistol

    Joined:
    Sep 3, 2015
    Posts:
    25
    In-Game or in the editor?
     
  4. TheDreamEXE

    TheDreamEXE

    Joined:
    May 14, 2015
    Posts:
    60
  5. awaterpistol

    awaterpistol

    Joined:
    Sep 3, 2015
    Posts:
    25


    This is it as localhost.
     
  6. HugoZandel

    HugoZandel

    Joined:
    Mar 11, 2014
    Posts:
    52
    Easy solution :
    Try changing localhost for your local ip (192.168.1.12 something like that).

    Probably a better idea in the long run :

    You can also get the NetworkManager to automagically pick the right ip with this piece of code.

    Code (CSharp):
    1.     private IPAddress LocalIPAddress()
    2.     {
    3.         if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
    4.         {
    5.             return null;
    6.         }
    7.  
    8.         IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
    9.  
    10.         return host
    11.             .AddressList
    12.             .FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
    13.     }
    14.  
    15.    void Start(){
    16.        networkAddress = LocalIPAddress().ToString();
    17.    }
    For this to work you have to extend the default NetworkManager

    Code (CSharp):
    1. public class YourNetworkManagerName : NetworkManager
    You also need to import some libs

    Code (CSharp):
    1. using System.Net;
    2. using System.Linq;
    3. using System.Net.Sockets;
     
  7. awaterpistol

    awaterpistol

    Joined:
    Sep 3, 2015
    Posts:
    25
    Could you explain how this works to allow my friends to join me without hamachi please? I don't understand the code.

    Also, for expanding the default Network Manager. Should I create a new script for this and include the finding the IP address there with the Network Manager as the base object?
     
  8. HugoZandel

    HugoZandel

    Joined:
    Mar 11, 2014
    Posts:
    52
    In this case you can simply change the ip inside the default network manager. Put your local ip in place of localhost.
     
  9. Valentinon13

    Valentinon13

    Joined:
    Jan 13, 2015
    Posts:
    10

    yeah you can make it i am still working on my own game you can private message my if you want !!!

    you need to make a database white xampp or wamp im using wamp because i am liking it more you need to have a dns i am using no - ip now and i have fixed my own script