UPDATE: i am still scratching my head over this. The way i see it, the Awake() function is only invoked when I load it in the Editor, but if I put the prefab Loading line into OnStartServer() it just doesnt load anything, presumably because it hasnt managed to load the prefab yet ... i think it is something to do with when it switches Scenes from the offline to online in NetworkManager, i think this script and others are being dropped because the DontDestroyOnLoad command wasnt called due to Awake not being called.
Hello everyone I am making a football game which you control one player from the team. It will connect 11v11 players per server (using a "Host" acting as server and client, and other clients connecting to them)
I believe I have followed the examples and information provided by Unity to the letter, but I can't seem to get it working properly.
The problem: My code seems to work fine, provided I open the 'Host' instance from the Unity Editor, but if I make the full build version the Host it doesnt work.
Strangely all my player-objects will all spawn and act exactly as I intended, but the ball will not spawn unless the 'Host' instance is the one opened inside Unity Editor. I've made the Ball a Network Identity, NetworkTransform etc and Registered Prefab in the NetworkManager in inspector.
Here's the code I am using to spawn the ball on the server, what could be the problem as I really have no ideas, thanks:
using UnityEngine;
using UnityEngine.Networking;
public class MatchdayManager : NetworkBehaviour {
GameObject ballPrefab;
private void Awake()
{
DontDestroyOnLoad(this);
ballPrefab = Resources.Load<GameObject>("Prefabs/Ball");
}
public override void OnStartServer()
{
Debug.Log("on server start called");
GameObject go = Instantiate(ballPrefab);
NetworkServer.Spawn(go);
}
}