Networking: using the smartphone as a controller

1704019--107202--mobile+controller.jpg
Hi

As you can see in the picture I’m trying to have different views/scenes/contents on each device. The host is showing one view and the other device showing another view with some buttons in it. The player controls the game using the smart phone.

Most of the tutorials I’ve seen so far are all about having the same scene/view showing in all devices. Is it possible to implement such a design in Unity?

Of course it’s possible. In worst case, you’d detect the device for control and enable another branch of GOs in the (same) scene.

1 Like

So this is what I did just in case anyone else is interested to know:
I assume you already know the basic of networking in unity, if not then go ahead and read either this book (Unity Asset Store - The Best Assets for Game Making) or the unity documentation manual.

I made a single scene with two cameras in it. Then chose one camera for viewing the game through(server) and the other camera for viewing my controller elements(client). I also used RPC to call functions on the server.

More detail:
Create a single scene with two cameras in it.
To set one camera for server and the other camera for the client you can do this:

//reference holders for cameras
public Camera serverCamera;
public Camera clientCamera;

And of course you need to drag and drop each camera to these two filed in the unity editor.

//set each camera
void OnConnectedToServer(){
serverCamera.enabled = false;
clientCamera.enabled = true;
}

Then you can have different GUI for each camera by doing so:

void OnGUI(){
if (Network.peerType == NetworkPeerType.Disconnected){
//some code here
}
else{
if (Network.peerType == NetworkPeerType.Connecting){
GUILayout.Label(“Connecting…”);
}
// differentiation between server and client
else if (Network.isServer){
//define your server GUI here.
}
else if (Network.isClient){
//define your client GUI here
}
}
}

2 Likes

Hi,

I’m already trying to create similar app with one significant difference - i want to have dynamic part of smartphone interface which changes in depend on current game situation. Is that still possible using the technology that You used?

And, if something changed, are RPCs still the best way for doing that kind of stuff?

This 3 year old thread only has example code from the obsolete legacy networking system. A new networking system was introduced in Unity 5.1 back in 2014. You should start a new thread.