Hey guys… So I have had everything working perfectly, but I am trying to play with this “Server only” option when starting my server in the UNet network manager.
Everything works 100% when I do “Host” (player + server) however, some weird things don’t work when I am “Server only”.
For example:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class ZombieSpawner : NetworkBehaviour {
public GameObject objectToSpawn;
public float spawnTime = 15f;
public float range = 15f;
private float t;
void Start() {
}
public override void OnStartServer() {
t = Time.time + spawnTime;
}
void FixedUpdate() {
if (!isServer)
return;
if (Time.time > t) {
CmdSpawnObject();
t = Time.time + 15f;
}
}
[Command]
void CmdSpawnObject() {
GameObject go = GameObject.Instantiate(objectToSpawn, new Vector3(transform.position.x + Random.Range(-range, range), transform.position.y, transform.position.z + Random.Range(-range, range)), Quaternion.identity) as GameObject;
NetworkServer.Spawn(go);
}
}
Simple script on a gameobject spawns enemies, now with the server only option it is like it does NOT run any FixedUpdate() or Update() methods.
What can I call other thatn FixedUpdate() or Update() to have timer things going on like I need?
Like seanr says you can’t use [Command] on the server side if that makes more sense… [Command] is called by clients. To run code on the server use the [Server] tag. The best way I can think to describe this is that [Command] is when your player is telling the server something like “Interact with the door” where as [Server] is server side updates and such - like AI - the player’s have no input as to what path the AI takes it is all server side. Although I need to clean up my code a bit maybe this will help.