Hi,
For some reason, the resources generator is working only for the host. When the client places the building with the resource generator class, it cannot find the RTS player to call the method to add the resources. Everything else is working; the client can place buildings, create units, and move them; the only thing is the resource generator. I copied the script:
‘’’
public class CrystalGenerator : NetworkBehaviour
{
[SerializeField] Health health = null;
[SerializeField] int crystalPerInterval = 10;
[SerializeField] float interval = 2f;
[SerializeField] RTSPlayer player;
float timer;
public override void OnStartServer()
{
timer = interval;
player = connectionToClient.identity.GetComponent<RTSPlayer>();
print(player);
health.ServerOnDie += ServerHandleDie;
GameOverHandle.ServerOnGameOver += ServerHandleGameOver;
}
public override void OnStopServer()
{
health.ServerOnDie -= ServerHandleDie;
GameOverHandle.ServerOnGameOver -= ServerHandleGameOver;
}
[ServerCallback]
void Update()
{
if(!hasAuthority) { return;}
timer -= Time.deltaTime;
if(timer <=0 && hasAuthority)
{
player.AddCrystal(player.GetCrystals() + crystalPerInterval);
timer += interval;
}
}
void ServerHandleDie()
{
NetworkServer.Destroy(gameObject);
}
void ServerHandleGameOver()
{
enabled = false;
}
}
‘’’
The player = connectionToClient.identity.GetComponent(); is in the start rather than the update, because I’m at the end of course, where we have a working lobby.
Thank you for the help.
The error I get, when I join from Unity, is a NullReferenceException for Player.AddCrystal(), it seems that OnStartServer() I’m not able to get the RTSPlayer component.