- Home /
Android mobile local multiplayer game via Wifi
Hi,
I am new to Unity Networking. I have been searching since past few days on how to connect my mobile with my friend's mobile via wifi for playing games. I want it to stay offline( no internet), ie, I dont want any Master Server like UNet or Photon uses. I researched a bit on UNet 5. They provide a way through which we can connect to the host on the same LAN network by specifying the the IP Address of the host.
My question is- Is there any way by which I can connect to the host without specifying the IP Address of the host. Since we are not using any kind of master server, It seems that there is no way we can keep a track of all the hosts created on the given LAN. Or if there is any way please let me know.
But still if you see doodle army mini militia, you will find that they have a way in which they can search through all the hosts created on the given LAN network. In mini militia, we create a wifi hotspot and all the other players join the same wifi network. Then One of the player hosts the game and all the other players joins the game without any trouble of putting the IP address.
I want the same functionality in my android game. The much i researched, it seems that its not possible by using UNet or Photon. I am not sure if I am correct or not. I went through many forums QA, but I could not get the answer to my question. I would be really glad if you could help me out.
Answer by Brijs · Dec 16, 2016 at 07:00 PM
Use NetworkDiscovery class of UNET.
1) Set broadcastData (going to be delivered to listeners) on host before starting broadcast.
2) Call Network discovery methods as written in NetworkDiscovery class doc and override OnReceivedBroadcast method as shown in doc. This method is called on clients when it listens broadcast from host/server.
3) OnReceivedBroadcast method has 2 parameters. First parameter is IP(of host/server) which is used to establish connection to server and second parameter data(can be host name) is broadcast data which is set in first step.
Now you have the IP of host /server so you do not have to specify IP address to connect to host.
This may help you.
@Brijs I,m developing an android game via Wifi and new to UNET as well, that's why I am unable to implement the steps mentioned above, it'd be great if you present a sample code for it. Please help me.
Answer by hamedham · Feb 13, 2018 at 04:15 PM
I think Every of answerers knows that which way is good for wifi connection t but no one of them can write an example code. thay doesnt know how to use it!
Answer by harikrishnan_annappilly · May 19, 2018 at 05:45 PM
So i just build a multiplayer game,I was planing to make a android version of it. So i included some UI buttons to it. But then i notices that Canvas wont piking the prefabs so i just put the canvas,buttons and event manager as child of the player charecter. It worked but then i see that it wont work as expected when connecting multiple devices. It is only able to control the latest player with latest deveice joined(latest means the last one which joined the game). So can some one help me to solve this ! Thank you
you need to see yaseen mujahid photon pun tutorial . there are only 4 videos . 5th is an extra one i havent use Unity own multiplayer system but you will get an idea what problem is there in photon u need to disable scripts of other players
Your answer
Follow this Question
Related Questions
Photon network won't join random room with a custom property 0 Answers
Photon objects not syncing 1 Answer
Light.color Sync ? 1 Answer
unity photon 2 not activate child of specific spawned player 0 Answers