Search Unity

UNET Networking Button

Discussion in 'UNet' started by bartek4213, Nov 25, 2020.

  1. bartek4213

    bartek4213

    Joined:
    Feb 6, 2020
    Posts:
    2
    Hi guys! I'm working on multiplayer game in UNET, i'm new in Unity. The case is that i have player Prefab, having UI inside. I know that can be wrong thinking but need it for project. So every player on server has Camera -> User UI -> Some chat, timer etc. Case is i want to make Voting menu so after creating Canvas i put Vote script on Player, then fill Canva with players who joined game in Grid as Buttons, then i want to have player Add vote for other player. Button has onClick event made in script i reminded before. After clicking there is syncvar for every player called votes, if someone click on button with for example 123321 nickname syncvar should be ++, it's working only for server and yeah i know that only server can update syncvar so i've tried with Command and Clientrpc, but it was saying something about network identity, ofc i was searching for the solution and people said that to make onClick listener in other script to handle commands but i can't figure it out.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I wouldn't make the UI a part of the Player prefab. Same with the Camera. Have them part of the scene, and have the Player prefab find these objects to hook up their references when the Player prefab spawns, or have scripts on these objects watch for the correct Player prefab to spawn. Use isLocalPlayer to check that you're on the correct Player prefab for this client.

    Why Commands or ClientRpc's aren't working would need the relevant code posted. Check for any errors in the player log or console as well.

    Also Unet is abandoned. If you're this early in developing your project, you should immediately switch to an alternative networking API. Since you're already learning Unet, then Mirror is a natural choice, since Mirror is a fork of the Unet HLAPI but is actually getting updates and fixes, unlike Unet. Tutorials for Unet mostly still apply to Mirror.
     
  3. bartek4213

    bartek4213

    Joined:
    Feb 6, 2020
    Posts:
    2
    Thanks for reply! I'll take your advice and modify that UI after having whole stuff working. I managed to solve my problem by:
    1. I had Cmd called in onClick event so that was the problem
    2. I'm closing voting menu when player adds vote so i moved Cmd method call from onClick to OnDisable method

    For my skills im deep into project (having deadline, but it's great lesson) to change it for mirror but i'll keep it in mind in the future. It was also recommended by my friend, but my first touch with unity was long time ago so i thought the amount of unet tutorials will be enought, but simply it wasn't best choice.