Search Unity

Problem with connection to a host using an android device (using Unet)

Discussion in 'UNet' started by marcos4503, Jan 22, 2017.

  1. marcos4503

    marcos4503

    Joined:
    Nov 1, 2015
    Posts:
    76
    First of all, thank you for your time.

    I'm creating a game that has a multiplayer mode that uses the local wifi network. I am able to create a host and connect two devices. So there's a problem where the game always hangs and closes when it connects to a host ...
    I will describe the situation better.

    - I use the unity editor to create a host, and I use my cell to connect to the host. When I create the host, the match starts and everything works perfectly. More when my device connects to the host it simply hangs.

    - When I create the host on my device and connect to the phone using the editor, everything works perfectly.

    - When I use an android device A to create the host, the match starts and everything works perfectly. More when device B connects to the host of device A, device B hangs.

    - I'm using Network Manager.

    - Below is the script I use to manage the connections:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class GERENCIADORLOCAL : MonoBehaviour {
    7.     public static string Nick;
    8.     public static bool StartHost;
    9.     public static bool StartClient;
    10.     public static string IP;
    11.     public static int Porta;
    12.     public static string Cena;
    13.  
    14.     private GameObject[] Local;
    15.     public int Ping;
    16.  
    17.     [Header("Elementos")]
    18.     [Space(10)]
    19.     public NetworkManager GerenciadorLocal;
    20.     public GameObject CastielPrefabMultiplayer;
    21.  
    22.     void Awake()
    23.     {
    24.         Local = GameObject.FindGameObjectsWithTag("LOCAL");
    25.         if (Local.Length >= 2)
    26.         {
    27.             Destroy(Local[0]);
    28.         }
    29.         DontDestroyOnLoad(transform.gameObject);
    30.     }
    31.  
    32.     void Start()
    33.     {
    34.         Nick = DATA.NomeDeUsuario;
    35.     }
    36.  
    37.     void Update()
    38.     {
    39.         Herois();
    40.         Server();
    41.     }
    42.  
    43.     void Herois()
    44.     {
    45.         if (DATA.HeroiAtivado == ("Castiel"))
    46.         {
    47.             GerenciadorLocal.playerPrefab = CastielPrefabMultiplayer;
    48.         }
    49.     }
    50.  
    51.     void Server()
    52.     {
    53.         Ping = GerenciadorLocal.simulatedLatency;
    54.  
    55.         if (Cena == ("Mapa De Teste"))
    56.         {
    57.             GerenciadorLocal.onlineScene = ("Teste");
    58.         }
    59.  
    60.         if(StartHost == true)
    61.         {
    62.             GerenciadorLocal.networkAddress = IP;
    63.             GerenciadorLocal.networkPort = Porta;
    64.             GerenciadorLocal.StartHost();
    65.             StartHost = false;
    66.         }
    67.  
    68.         if(StartClient == true)
    69.         {
    70.             GerenciadorLocal.networkAddress = IP;
    71.             GerenciadorLocal.networkPort = Porta;
    72.             GerenciadorLocal.StartClient();
    73.             StartClient = false;
    74.         }
    75.     }
    76. }
    If you can help me, please post a reply here on the topic, I really need some help! If you know of any alternative way to create a local multiplayer, please show me.

    I am sorry for my english.
    I'm Brazilian.
    I searched for answers in my community but found nothing!

    Again, thank you for your time!