I am working on a multiplayer game using UNET. Every time i host a match by playing the game in the editor, every player that joins is considered as server and the game works as intended. If i host a match by using a built game (not using the Unity editor), every player that joins is considered a client and they all spawn in the same network spawn position and also, every time that my enemy spawner tries to instantiate an enemy prefab, i get an error message.
I really can't understand what's going on.
I have tried following other tutorials online but nothing helped. I'll list the code and the errores below.
//To check if a player is a client or a server, i wrote this code in the //player setup script:
"if (isServer)
Debug.Log("server");
else
Debug.Log("Client");"
//this code is used in the player scirpt to get damaged when is hit by an //enemy bullet
private void OnTriggerEnter2D(Collider2D hitInfo)
{
if (hitInfo.tag == "Enemy" || hitInfo.tag == "EnemyBullet")
{
RpcTakeDamage(10, "hit by enemy");
}
}
[ClientRpc]
public void RpcTakeDamage(int _amount, string _sourceID)
{
if (!isHit)
{
StartCoroutine("HurtColor");
currentHealth -= _amount;
Debug.Log(transform.name + " now has " + currentHealth + " health ");
if (currentHealth <= 0)
{
Die(_sourceID);
}
}
}
//The Die function so far just destroys the player game object
//these errors show up when i join the game hosted by the built game
"Network configuration mismatch detected. The number of networked scripts on the client does not match the number of networked scripts on the server. This could be caused by lazy loading of scripts on the client. This warning can be disabled by the checkbox in NetworkManager Script CRC Check."
"CRC Local Dump PlayerSetup : 0"
"Trying to send command for object without authority."
//this happens every time my enemy spawner tries to spawn an enemy when the //game is hosted by a built game and every player is considered as a client //The enemy prefab still gets spawned and moves as intended
"SpawnObject for EnemyUpRight(Clone) (UnityEngine.GameObject), NetworkServer is not active. Cannot spawn objects without an active server."
//When an enemy bullet hits a player, instead of getting damaged an error shows up
"RPC Function RpcTakeDamage called on client."