Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Help with Weapon Synchronization

Discussion in 'Multiplayer' started by realkillerx, Jun 20, 2018.

  1. realkillerx

    realkillerx

    Joined:
    Nov 9, 2013
    Posts:
    10
    Hello there,

    I am *somewhat* new to Unity, however i used it before and this is my first larger scale UNET project.

    I have set up a script that checks for possessed weapons, and i also have created a placeholder cube that sets CrowbarGot to true, and within my possessed weapons script, it constantly checks if CrowbarGot is true, and if it is, enables the melee gameobject that i have attached to my Player object, and this is where things get problematic.

    When i host the game with a client on it, when i go to the cube and get my crowbar, it appears without problems on my screen, however the client can not see it.

    I hope anyone has the solution to this because i tried a lot of stuff that didnt work, thanks in advance
     
  2. realkillerx

    realkillerx

    Joined:
    Nov 9, 2013
    Posts:
    10
    Just realized this might not be the best place to ask, a moderator should delete this
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    We'd need to see your script(s) in order to help with your question. It likely depends on how you are notifying clients that they should display that crowbar.
     
  4. realkillerx

    realkillerx

    Joined:
    Nov 9, 2013
    Posts:
    10
    Code (CSharp):
    1.     public bool CrowbarGot;
    2.     public GameObject Crowbar;
    3.    
    4.  
    5.     // Use this for initialization
    6.     void Start () {
    7.        
    8.     }
    9.    
    10.     // Update is called once per frame
    11.     void Update () {
    12.  
    13.         if (CrowbarGot == true)
    14.         {
    15.             Crowbar.SetActive(true);
    16.         }
    17.     }
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Seeing that you have no networking code here at all, that would be why no other players are seeing anything change. You're going to need a way to tell the server to tell the other clients to also enable the crowbar attached to your player. Generally with Unet you'd do that with a Command to the server from a NetworkBehaviour attached to your Player GameObject, and then have the server notify the clients via a ClientRpc, or SyncVar possibly with a SyncVar Hook method called.

    Alternatively you could do it all with Unet Messages instead of Commands, ClientRpc's, or SyncVars.