Hallo community,
i have two problems in the following case and need your help.
First i made a unity project with only one empty gameobject with this script:
void Start()
{
Network.InitializeServer(4, 25000, Network.HavePublicAddress());
MasterServer.RegisterHost(typeName, gameName);
}
I create the masterserver on the windows 2008 server, and everything is right.
Next i made a unity project for the players. Theres one script on an empty gameobject to connect to the server:
private HostData[] hostList;
public GameObject player;
void Start()
{
if(!Network.isClient && !Network.isServer)
RefreshHostList();
}
void RefreshHostList()
{
MasterServer.RequestHostList(typeName);
}
void OnMasterServerEvent(MasterServerEvent msEvent)
{
if (msEvent == MasterServerEvent.HostListReceived)
hostList = MasterServer.PollHostList();
}
void JoinServer(HostData hostData)
{
Network.Connect(hostData);
}
void OnConnectedToServer()
{
Debug.Log ("Joined Server");
Network.Instantiate (player, new Vector3 (20, 2, 5), Quaternion.identity, 0);
}
void OnGUI()
{
if (!Network.isClient && !Network.isServer)
{
if (hostList != null)
{
for (int i = 0; i < hostList.Length; i++)
{
if (GUI.Button(new Rect(400, 100 + (110 * i), 300, 100), hostList[i].gameName))
JoinServer(hostList[i]);
}
}
}
}
I can connect to the server. If a player connect to the server, a player-object will be intiantiate and synchronisate him with the server and other players. But if it test it with 2 players, i can move and look around, but other players stay on the spawnpoint and dont move.
The player-object is so constructed:
empty gameobject with rigidbody, charcontroller, network view (reliable delta …) and a script (see on bottom)
capsule
capsule
…
sphere with network view (off)empty gameobject with camera and network view (off)
The player script:
private float speed = 6.0f;
private float jumpSpeed = 10.0F;
private float gravity = 40.0F;
private Vector3 moveDirection = Vector3.zero;
void Update () {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded && networkView.isMine) {
moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move (moveDirection * Time.deltaTime);
}
void OnApplicationQuit() {
Destroy (this.gameObject);
}
So, i know its very confused and i have two problems:
- No synchronisation between players
- The player-objects wont be destroid if they leave
Thank you for your help.