Message Passing b/w “LAN Server Only” and “LAN Client” on Different Scenes in Unity

by syed ali   Last Updated May 15, 2018 20:13 PM

I want to pass message back and forth on client and server which are on different scenes, how can I do that in Unity?**

Following is my Scenario:- I have 5 scenes-

  1. BaseScene (2) OfflineScene (3) OnlineScene (4) ClientOnline (5) ServerOnline.

All these scenes have button having text of the names of the scenes. On Base Scene, I have add empty game object on which i have placed "customNetworkScript" which extends from "NetworkManager" script and also placed "Network Manager HUD" on it. Following is the code which i have placed in "customNetworkScript":-

public class customNetworkScript : NetworkManager {

        public override void OnClientSceneChanged(NetworkConnection conn)
                SceneManager.LoadScene("ClientOnline", LoadSceneMode.Single);
                ClientScene.AddPlayer(conn, 0);

            public override void OnServerSceneChanged(string sceneName)
                SceneManager.LoadScene("ServerOnline", LoadSceneMode.Single);

I have placed "OfflineScene" and "OnlineScene" in the fields, named "Offline Scene" and "Online Scene" in "Network Manager" component. Also have placed an empty prefab in "Spawn Info" in "customNetworkScript" and it has component "Network Identity" on it. Now when i run project, on one instance, I click on "LAN Server only" and on another instance, I click on "LAN Client". And I get my respective scenes on both the instances -> "ServerOnline" appear on instance where I click "LAN Server only" and "ClientOnline" appear on other instance. What I want is, when i click on "ServerOnline" button, a message string will pass on to "ClientOnline" scene and same happens in backward direction when i click on "ClientOnline" button.

I have tried "Rpc" and "Command" but they only work when I click on "LAN Host" instead of "LAN Server Only". I have tried very hard but couldn't find anything useful. It will be a great pleasure if someone explain to me in detail along with the code, how can I achieve this.

ThankYou Very Much for Your Time.

Related Questions