Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sync a Video on Client machines

Discussion in 'Multiplayer' started by shantanu01, Jun 14, 2018.

  1. shantanu01

    shantanu01

    Joined:
    Jan 15, 2018
    Posts:
    4
    Hello All,
    I have 4 players joining on a local lan network. My player camera is orthographic. Player controls are disabled. Each player is spawn at a fixed distance from each other. Say for example player 1 is spawned at (-10, 0,0), player 2 is spawned at (0,0,0), player 3 is spawned at (10,0,0), player 4 is spawned at (20,0,0).
    myproblem.png
    In front of each player I have a Quad to which a video player component is attached and a video clip is to be played.

    I tried syncVars/rpc functions running on the server and client as well, but I am not able to get the desired effect.The video starts only on the server or the client if I press the SPACEBAR as I have added a code to play the video or pause it.

    Well I press Spacebar the video should start playing and all clients must be updated with the current frame of the video its on.

    When all the players are joined I want to start playing this video in sync so that each player sees a part of the video on their monitor screen (orthographic camera).

    I completed this https://unity3d.com/learn/tutorials...3.2034224582.1528794218-1204989338.1526534996
    tutorial example to understand how Network Multiplayer works in unity.


    Any kind of help will be highly apriciated.

    Thanks,
    Shantanu
     
  2. BrunoPuccio

    BrunoPuccio

    Joined:
    Dec 13, 2017
    Posts:
    22
    did you try something like this?

    Code (CSharp):
    1.     void Update()
    2.     {
    3.         if (Input.GetKeyDown(KeyCode.Space))
    4.         {
    5.             if (isServer)
    6.                 RpcPlayVideo();
    7.             else
    8.                 CmdPlayVideo();
    9.         }
    10.     }
    11.  
    12.     [ClientRpc]
    13.     void RpcPlayVideo()//server calls this method
    14.     {
    15.         StartPlaying();
    16.     }
    17.  
    18.     [Command]
    19.     void CmdPlayVideo()//clients call this method
    20.     {
    21.         RpcPlayVideo();
    22.     }
    23.  
    24.     void StartPlaying()
    25.     {
    26.         //play or pause video locally
    27.     }
     
  3. SDTF

    SDTF

    Joined:
    Sep 3, 2020
    Posts:
    9
    This helped me! thank you
     
  4. leavittx

    leavittx

    Joined:
    Dec 27, 2013
    Posts:
    176