Hi all,
I’m having an odd scenario with Mirror / Unet where the isServer boolean is returning false when it’s called from the server.
Here’s the basic skeleton of the code I’m working with.
class Player : NetworkBehavior
{
void Update()
{
if (isServer)
{
CheckHasPlayer();
}
}
[Server]
void CheckHasPlayer()
{
//logic to see if a player has a server side player object
if (player == null)
{
PlayerSpawner.SpawnPlayer();
}
}
}
class PlayerSpawner : NetworkBehavior
{
[Server]
static void SpawnPlayer()
{
GameObject newPlayer = Instantiate(playerPrefab);
Shooter shooter = newPlayer.GetComponent<Shooter>();
shooter.Initialize();
}
}
class Shooter : NetworkBehavior
{
[Server]
public void Initialize()
{
if (!isServer)
{
print ("NOT ON SERVER");
}
}
}
“NOT ON SERVER” is being printed and I don’t understand how.
The whole code string starts in a check to see if it’s on the server. All of the functions are designated as only being able to be called by the server. But, by the time it reaches “Initialize”, isServer is false.
It doesn’t make any sense to me and is leaving me stuck.
Thoughts?