0
\$\begingroup\$

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.Ready(conn);
                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.

\$\endgroup\$
0
\$\begingroup\$

After hours of research and hard work, finally find a solution for my problem. I will refer to this asset if someone still stuck on it:

This asset is well documented and will tell you all about how you can do dedicated/pure server and client networking:-

Asset Link

If someone still don't understand it feel free to ask me. I will try my best.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.