Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Vanderlolbroek · May 20, 2019 at 03:28 PM · scripting problemnetworkingclienthosting

why do I have so many bugs in my custom networkmanager HUD script

I got many bugs in my custom network manager HUD script and I don't know what is the problem. I think because if a client leaves the server the server doesn't know the client has left. But I have tried many things but I don't know what the problem really is.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 using System.Net;
 using System.Net.Sockets;
 using UnityEngine.SceneManagement;
 using TMPro;
 
 
 public class NetworkManagerHUDCustom : NetworkBehaviour
 {
     public GameObject button1Host;
     public GameObject button2Host;
 
     public GameObject button1Join;
     public GameObject button2Join;
 
     public GameObject canvas;
     public GameObject buttons;
 
     public string ip;
     public string shortIp;
 
     public TMP_Text ipText; 
     public TMP_InputField ipInput;
 
     public bool updateblabla;
     private bool isConnected;
 
     // Runtime variable
     bool m_ShowServer;
 
     public NetworkManager manager;               
 
     void Awake()
     {
         manager = GameObject.FindObjectOfType<NetworkManager>();
         MakeShortIp();
         FirstPartOfIp();
 
         manager = NetworkManager.singleton;
     }
 
     private void Update()
     {
         //manager.IsClientConnected
         if (!ipInput)
         {
             return;
         }
         else
         {
             ip = FirstPartOfIp() + ipInput.text;
         }
 
         if (SceneManager.GetActiveScene().name == "Main")
         {
             canvas.SetActive(true);
             buttons.SetActive(true);
         }
         else
         {
             canvas.SetActive(false);
             buttons.SetActive(false);
         }
     }
 
     public string FirstPartOfIp()
     {
         string localIp = LocalIPAddress();
         while (localIp.Substring(localIp.Length - 1, 1) != ".")
         {
             localIp = localIp.Remove(localIp.Length - 1);
         }
         return (localIp);
     }
 
     public void MakeShortIp()
     {
         string localIp = LocalIPAddress();
         while (localIp.Substring(localIp.Length - 1, 1) != ".")
         {
             shortIp = shortIp.Insert(0, localIp.Substring(localIp.Length - 1, 1));
             localIp = localIp.Remove(localIp.Length - 1);
         }
         ipText.text = shortIp;
     }
 
     public string LocalIPAddress()
     {
         IPHostEntry host;
         string localIP = "";
         host = Dns.GetHostEntry(Dns.GetHostName());
         foreach (IPAddress ip in host.AddressList)
         {
             if (ip.AddressFamily == AddressFamily.InterNetwork)
             {
                 localIP = ip.ToString();
                 break;
             }
         }
         return localIP;
     }
 
     public void HostParty(GameObject button)
     {
         if (!manager.IsClientConnected() && !NetworkServer.active && manager.matchMaker == null)
         {
             if (UnityEngine.Application.platform != RuntimePlatform.WebGLPlayer)
             {
 
                 manager.StartHost();
 
             }
         }
         SwitchButton(button1Host, button2Host);
         button1Join.SetActive(false);
         button2Join.SetActive(false);
     }
 
     public void JoinParty(GameObject button)
     {
         if (!manager.IsClientConnected() && !NetworkServer.active && manager.matchMaker == null)
         {
             manager.networkAddress = ip;
             manager.StartClient();
         }
 
         SwitchButton(button1Join, button2Join);
         button1Host.SetActive(false);
         button2Host.SetActive(false);
     }
 
     public void LeaveParty(GameObject button)
     {
         if (manager.IsClientConnected())
         {
             manager.StopMatchMaker();
             manager.StopClient();
         }
 
         SwitchButton(button2Join, button1Join);
         button1Host.SetActive(true);
         button2Host.SetActive(true);
     }
 
 
     public void StopHostParty(GameObject button)
     {
         if (NetworkServer.active)
         {
             if (manager.IsClientConnected())
             {
                 manager.StopHost();
             }
         }
 
         SwitchButton(button2Host, button1Host);
         button1Join.SetActive(true);
         button2Join.SetActive(true);
     }
 
     public void SwitchButton(GameObject obj1, GameObject obj2)
     {
         obj1.SetActive(false);
         obj2.SetActive(true);
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

222 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Planning 2-4 player game for iPad; do I want / need Photon? 0 Answers

Networking not connecting anymore 0 Answers

Unity UDP freezes if disconnected from server 2 Answers

Alternative to RPC for destroying objects across a network 0 Answers

Command not executing for all clients 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges