- Home /
Unity UNET how to connect to local network(same wifi)
So I'm trying to make game in which you can connect to friends if they are connected to same wifi router without internet. On same computer I can host game an then join in other game window but I can't figure out how to join between two computers on same wifi. Anyone can help? Documentation, sample projects, tutorial anything?
Answer by Endless_Aftermath · Oct 30, 2015 at 02:34 PM
Here's a login program that I made from a youtube tutorial here... https://youtu.be/v4cXuiZyJQ8 .
I commented a lot of this out to help teach my son learn networking. This tutorial will show (pretty simply) how to connect and share information over LAN/WiFi. Hope this helps.
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour
{
public string ip = "169.254.17.167";
public int port = 25000;
void OnGUI()
{
//if the player is NOT connected
if(Network.peerType == NetworkPeerType.Disconnected)
{
//this is temporary for input of the ip address
//find out your ip address and assign it here during gameplay
ip = GUI.TextField(new Rect(200, 100, 100, 25), ip);
port = int.Parse(GUI.TextField(new Rect(200, 125, 100, 25),""+ port));
//if the player wants to connect to a server
if(GUI.Button(new Rect(100,100,100,25), "Start Client"))
{
//this is where we actually connect to the server
Network.Connect(ip, port);
}
//if the player wants to start a server
if(GUI.Button(new Rect(100,125,100,25), "Create Server"))
{
Network.InitializeServer(10, port,false);
}
}//end of "if the player is NOT connected"
else //if the player IS connected
{
if(Network.peerType == NetworkPeerType.Client)
{
//letting the player know that they are a client to a server
GUI.Label(new Rect(100,100,100,25), "Client");
//if the player wants to disconnect
if(GUI.Button(new Rect(100,125,100,25), "Logout"))
Network.Disconnect(200);//the 200 is in milliseconds for the disconnect
}
if(Network.peerType == NetworkPeerType.Server)
{
//letting the player know that they are a server
GUI.Label(new Rect(100,100,100,25), "Server");
//this shows how many people are connected to your server
GUI.Label(new Rect(100,125,100,25), "Connections: " + Network.connections.Length);
//if the player wants to disconnect
if(GUI.Button(new Rect(100,150 ,100,25), "Logout"))
Network.Disconnect(200); //the 200 is in milliseconds for the disconnect
}
}//end of "if the player IS connected"
}
}
It's not UNET, but thanks a lot, I just typed IP ins$$anonymous$$d of localhost and now I can connect via wifi. Thanks!
Hi, When you say in your script :
(37) //letting the player know that they are a client to a server
(48) //letting the player know that they are a server
What do you mean by "they are a..." ? Do you mean "there is a..." or "he is a..." or something else ?
Thank you.
Hi @$$anonymous$$dless_Aftermath, Thank you very much for taking the time to share this with us. It works marvelous well and it is simple enough, a fine combination. I only added a piece of code to take the local IP address to show;
void Start()
{
string localHost = Network$$anonymous$$anager.singleton.networkAddress;
IPHostEntry host;
string localIP = "";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ipGO in host.AddressList)
{
if (ipGO.AddressFamily == AddressFamily.InterNetwork)
{
ip = ipGO.ToString();
Debug.Log(ip);
break;
}
}
}
Answer by martinajain11 · Oct 15, 2018 at 12:37 PM
I have Linksys WRT1900AC AC1900 Dual-Band Wi-Fi Router" Linksys router, After the installation, I connected a Lan with a modem to access an internet via Laptop but I can't find the local address to connect two different systems. It seems like I'm not able to connect with them. Can I contact Linksys support experts at https://www.routertechnicalsupportnumbers.com/linksys-router-support/ or not. Your support is precious to me.
Answer by tanjawl45645 · Jul 18, 2019 at 10:40 AM
I was trying to do it, but before it succeeds it creates an error, may I ask how can I resolve this or could you please provide me a brief description to the point. Besides this should it possible to take help for the issue from D-Link Router Customer Support from http://www.routercustomercare.co/blog/how-to-fix-d-link-router-errors-103/ please reply me.,I was trying your tips, but unfortunately, there occurs an issue due to which it cannot be possible. Could you please, provide me the brief description or points? Is it able to get help from D-link router customer support from http://www.routercustomercare.co/blog/how-to-fix-d-link-router-errors-103/ . please reply me .
Answer by evagrey · Jul 29, 2019 at 11:36 AM
Even I made a same attempt to do so, however, I failed to succeed in it. But to secure my all online activity, I download AOL Shield Support which is working as a safety guard for all my online works. Besides, for my further queries I visited their website for help and found it useful.
Answer by eja67 · Oct 25, 2020 at 08:49 AM
Hi @Endless_Aftermath, i done but in my phone i can not connect to PC, can you help me to do that!,
Your answer
Follow this Question
Related Questions
Client side Player prefab spawned by overriding GameManager return false for isLocalPlayer 0 Answers
Is unity uses rendering from the cpu or gpu ? 2 Answers
how can i pickup a weapon and drop it on certain key press?(unet) 0 Answers
How can a client connect more players to a network game? 1 Answer
Time.time is influenced by the performance? Can i use it in a multiplayer game? 1 Answer