Search Unity

Third Party Mirror update server object from client

Discussion in 'Multiplayer' started by Zelloxy, Sep 22, 2021.

  1. Zelloxy

    Zelloxy

    Joined:
    Nov 15, 2013
    Posts:
    3
    2 questions actually:

    1. When the mouse button is let go the "DestroyGrapple" is called from client and I want to destroy the earlier created GrapplingHookLinePrefab.
    2. "CreateHookLine" is run on client when button is pressed, I then want to create my prefab on server and keep updating the Origin with my position of my GunTransform. I don't want to have to sync the positions for these since GunTransform is already a network identity that I sync.

    Code (CSharp):
    1.  
    2.  
    3. private GameObject _line;
    4.  
    5. [Command]
    6.     void CreateHookLine(Vector3 position, Quaternion rotation, GameObject playerOwner)
    7.     {
    8.         _line = Instantiate(GrapplingHookLinePrefab, position, rotation);
    9.         var lineScript = _line.GetComponent<GrapplingHookLine>();
    10.         lineScript.PlayerOwner = playerOwner;
    11.         lineScript.Origin = GunTransform;
    12.         lineScript.Target = _grapplePoint;
    13.         NetworkServer.Spawn(_line, playerOwner);
    14.     }
    15.  
    16. [Command]
    17.     void DestroyGrapple()
    18.     {
    19.         NetworkServer.Destroy(_line);
    20.     }
    21.  
    22.  
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Your post has 2 statements, and 0 questions. What are your questions?