- Home /
The question is answered, right answer was accepted
New Unity 5.1 Networking :- Spawning is not synchronized!!!!
Hello, I am a junior undergraduate student and I am new to UNITY and Game development.
I have problem spawning players in my game. I am using new unity Networking. I have set two empty gameObjects as StartPosition(New Network Components) in my Scene. When i connect either from client or server the local player gets spawned at 1st SpawnPosition and the other at 2nd SpawnPosition (although they appear correct in game). But it's actually not like what i have expected. It appears that in both game application myplayer is at 1st SpawnPosition and the other at 2nd SpawnPosition. i.e spawning is not synchronized. Please help me through it. Thanks in advance.
here is what i am trying to achieve for my two player game...
public class Spawner : NetworkManager {
public Transform[] spawnSpots;
public override void OnServerAddPlayer (NetworkConnection conn, short playerControllerID)
{
if(isServer)//isServer doesn't exist
{
GameObject player = (GameObject)Instantiate(base.playerPrefab,spawnSpots[0].position,spawnSpots[0].rotation);
NetworkServer.AddPlayerForConnection(conn,player,playerControllerID);
}
else if(isClient)//isClient doesn't exist
{
GameObject player = (GameObject)Instantiate(base.playerPrefab,spawnSpots[1].position,spawnSpots[1].rotation);
NetworkServer.AddPlayerForConnection(conn,player,playerControllerID);
}
}
}
I am not not using this code it is just like a pseudocode of what i want to achieve. In fact isServer and isClient doesn't exist in this scope.
I am trying to making a game in which two players spawn facing each other somewhat like in a capture the flag type of games. In the server game application(also client,let's call it "client1") 1st player joins and spawns at 1st spawn point. The second player("client2") joins and spawns in 2nd spawn point. But in the Second player's Application window("client2"), 2nd player spawns at 1st spawn point(here i want to spawn at 2nd spawn point so that it stays synchronized with the server) and 1st player(server player) spawn at 2nd spawn point(which should be at 1st spawn point).
i have marked the two spawn points as "Network Start position"(The component that comes in the new unity 5.1 networking). And i am using "round robin" as "player spawn method"($$anonymous$$ethod in new unity 5.1 networking component Network$$anonymous$$anager).
I think this explains the problem better.
From the code you posted I cant see why it won't be synchronised.
As long is IsServer and IsClient is set correctly on connecting and spawnSpots[] is not set randomly, then your way should be working.
To make it random you could make the server decide what spot to spawn on, then sent the other spot to the client to spawn on.
Yeah Casper$$anonymous$$, it makes sense here, but its not the correct way to solve it. isServer and isClient doesn't exist in the class scope.
Answer by RZ0895 · Jul 01, 2015 at 06:49 AM
Sorry guyz for trouble, after a lot of debugging and study found out my noob mistake.
i was finding GameObject with name and turning his camera and controller on. But it always found the server player first and turned his controller and camera on. So it appeared that they spawned like that.
Answer by psistalk · Jun 30, 2015 at 11:09 AM
if your using UNET try this
using UnityEngine.Networking;
public class Spawner : NetworkBehaviour {
NetworkBehaviour derives from Monobehavior
then
if(isLocalPlayer){}
if(isServer){}
isLocalPlayer is not assigned till the new Player(the prefab we set in network manager in UNET) is spawned. So, can't get it to work.
I have spawned player successfully :) But trying to display own player on screen centre position and other joined player should be available either left or right. Each player can see his position on center in his app. Is it possible ? I am using photonview.is$$anonymous$$e method. But not succeed.
please help