Click here to Skip to main content
15,881,044 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, 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":-
C#
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.

What I have tried:

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.
Posted
Updated 15-May-18 16:07pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900