Ola pessoaal!!
Vamos lá
Crie uma pasta chamada Scripts no seu Assets
La add um C# Script com o nome de PlayerSpawner
e cola esse codigo
Crie outro C# Script com o nome de Networking
e cola esse codigo
Pronto só isso !!
Vamos lá
Crie uma pasta chamada Scripts no seu Assets
La add um C# Script com o nome de PlayerSpawner
e cola esse codigo
- Código:
using UnityEngine;
using System.Collections;
public class PlayerSpawner : MonoBehaviour {
public Transform player;
void OnServerInitialized(){
SpawnPlayer ();
}
void OnConnectedToServer(){
SpawnPlayer ();
}
void SpawnPlayer(){
Network.Instantiate (player, transform.position, transform.rotation, 0);
}
void OnPlayerDisconnected(NetworkPlayer player){
Network.RemoveRPCs (player);
Network.DestroyPlayerObjects (player);
}
void OnDisconnectedFromServer(NetworkDisconnection info){
Network.RemoveRPCs (Network.player);
Network.DestroyPlayerObjects (Network.player);
Application.LoadLevel (Application.loadedLevel);
}
}
Crie outro C# Script com o nome de Networking
e cola esse codigo
- Código:
using UnityEngine;
using System.Collections;
public class Networking : MonoBehaviour {
string ServerIP = "127.0.0.1";
int ServerPort = 30000;
void OnGUI(){
if (Network.peerType == NetworkPeerType.Disconnected) {
if(GUILayout.Button("Connect")){
Network.Connect(ServerIP, ServerPort);
}
if(GUILayout.Button("New Server")){
Network.InitializeServer(32, ServerPort, false);
}
}
else
{
if(GUILayout.Button("Disconnect")){
Network.Disconnect();
}
}
}
}
Pronto só isso !!