- Home /
How to connect to hosted scene (Multiplayer)
So I have followed some tutorials on youtube on how to connect to a server and also how to set up a server, but now I wanna know how the client that is connecting to the host can go right into a scene that the host is currently hosting kinda.
Anyhow, here's my script (C#):
using UnityEngine;
using System.Collections;
public class Network_Menu : MonoBehaviour {
public string IP = "127.0.0.1";
public int Port = 25000;
void OnGUI()
{
if(Network.peerType == NetworkPeerType.Disconnected)
{
if(GUI.Button(new Rect(100,100,100,25),"Start Client"))
{
Network.Connect(IP,Port);
}
if(GUI.Button(new Rect(100,125,100,25),"Start Server"))
{
Network.InitializeServer(4,Port);
}
}
else {
if(Network.peerType == NetworkPeerType.Client)
{
GUI.Label(new Rect(100,100,100,25), "Client");
if(GUI.Button(new Rect(100,125,100,25), "Logout")){
Network.Disconnect(250);
}
}
if(Network.peerType == NetworkPeerType.Server)
{
GUI.Label(new Rect(100,100,100,25), "Client");
GUI.Label(new Rect(100,125,100,25), "Connections: " + Network.connections.Length);
if(GUI.Button(new Rect(100,150,100,25), "Logout")){
Network.Disconnect(250);
}
}
}
}
}
Answer by Ashkan_gc · Jun 28, 2013 at 12:08 PM
In OnPlayerConnected you can send the connected client as a RPC, name of the scene that he/she should load. Then in client in RPC just check if the sender is the server and if yes then load that scene.
Ok, so I'm going to assume OnPlayerConnected is a function, but what is a RPC? Could you give me an example code?
After you read this and everything it links to, ask again: http://docs.unity3d.com/Documentation/Components/class-NetworkView.html
I've actually managed the host and the clients to load the scene but they all play individually and not together on the same scene, help please?
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
setup a php master server 2 Answers
how to test your multiplayer game 2 Answers
C# How to have a gun select 1 Answer
Unity3D Photon movement synchronization 0 Answers