Search Unity

Testing of Multiplayer in Android Devices.

Discussion in 'Multiplayer' started by Waterbyte, Mar 26, 2016.

  1. Waterbyte

    Waterbyte

    Joined:
    Mar 25, 2016
    Posts:
    2
    This post is for newbies learning multiplayer from official Unity Tutorials and implementing them in Android Devices. It assumes that you have completed atleast one of the official multiplayer Unity Tutorial.
    In official Tutorials, there is a little to nothing about multiplayer testing in Android Devices, (offcourse, i am talking about Wifi Hotspot Network). While following the tutorials, i personally got very confused as i am both new to Unity and Networking and have spent countless hours just to figure things out.

    Let's go straight to topic.

    1. While following official tutorial you would come across Network Manager. In it's Network Info, you would see Network Address and Network Port Field. If you don't know about Network Address and Port, then in first place you should rethink your decision of making multiplayer games. Nevertheless, Google about them. Network Address is the address of server and this is what client would be prompted to connect to if you follow official Tutorial.

    2. You would see "localhost" written in Network Address which is a Loopback Address. (Google about it too.)
    While, "localhost" is great for running local instances of game i.e. in a scenario where both your devices are running in same machine. However, if you are trying to test in android device, this is no good.

    3. Do everything as stated in tutorial. "Localhost" is the Network Address and leave Network Port as it is. Install your game in two different android devices. Open Hotspot in one and connect the other Phone to the same network. You would be assigned a Network I.P. Now in First Phone, Click on Lan Host(H) in Network Manager HUD. This would start a dual configuration on your first device i.e. it would be both a Server and Client simultaneously. Since your Server and Client is in the same device, you could use multiplayer in that device.

    4. In your other device, Open your Network Manager HUD. Now you would see "localhost" written in LAN CLIENT option. This is not good since the server is in first device is localhost points to your device only. So Instead of localhost you need to enter the I.P. Address of the First Device(This has server).

    5. Google to find the ways of getting I.P. address. Normally, in most cases the scenario is like this.

    * Go to Wifi Settings and click on the Wifi Connection that your device is connected to. It would show your I.P. address i.e. I.P. address allocated to your device. It would be something like this: 192.168.XXX.XXX.
    In most cases, the IP address of the first device( device having server) would be 192.168.XXX.1 (This is what you need to enter in LAN CLIENT option).

    Hope, this helps somebody. Feel free to Comment and correct any errors.
     
    aqib-nawaz-003 and zergnick like this.
  2. degeta

    degeta

    Joined:
    Sep 14, 2016
    Posts:
    2
    In the screenshot, it shows a simple game. in this game P1 is the user and P2 acts like a bot. P1 has the option to choose 3 buttons at the bottom and when he selects any one of those, it is compared with P2’s choice(P2’s option is chosen automatically in the script using Random()).So as of now its like playing with CPU opponent and not with a real player. So i wanted to make this a multiplayer, where the opponent will choose one of the options and player will also choose and a winner will be decided based on a logic. I have gone through the UNET docs, completed the multiplayer sample its connecting well and fine. I tested it on the two phones and its working too. So can you help me in creating this multiplayer in unity? It would be really helpful.The network connectivity I’m prefering is just local Wifi hotspot and not internet.
     

    Attached Files:

  3. aqib-nawaz-003

    aqib-nawaz-003

    Joined:
    Jan 30, 2017
    Posts:
    1
    Thanks a lot man for sharing this I appreciate it keep it up I am new to Unity and it helped me a lot to solve my problem
     
  4. fonko

    fonko

    Joined:
    Mar 20, 2014
    Posts:
    23
    Still... isn't there a way using some service of unity? like wtih a small amount of devices only for testing? im looking for something like this and it got me for hours spining around, i want to break something
     
  5. fonko

    fonko

    Joined:
    Mar 20, 2014
    Posts:
    23
    Well, i figure it out. im so dumb.
    With the Network HUD you have the chance to create an internet room, there you can set a name and then in the other instance of the game just join that room over the internet. Done.

    the url wher it creates this "server" seems to be manage from Network Manager controller under network info Match maker host ;)