- Home /
Question by
Graybad1 · Aug 02, 2016 at 11:58 AM ·
networkingspawncommand
Cmd is called on Server ERROR!?!!
Everything works if you are the host, but id you are a client, you get this error for every item it tries to spawn. The ItemSpawner class is Located on Empty Objects, Just containing the NetworkIdentity, NetworkTransform, and the class. Here are the classes:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
public class ItemSpawner : NetworkBehaviour{
public List<Item> items = new List<Item>();
public virtual void Init (){
Debug.Log ("Didn't Initialize Spawner!");
}
public void addItem(Item item){
items.Add (item);
}
int idOfSpawnedItem;
void Start(){
Init ();
Item spawnedItem;
spawnedItem = items [Random.Range (0, items.Count)];
CmdSpawnItem (spawnedItem.id);
}
[Command]
public void CmdSpawnItem(int itemId){
GameObject spawning = (GameObject)Instantiate (ItemHandler.getItemById(itemId).prefab, transform.position, Quaternion.identity);
UnityEngine.Networking.NetworkServer.Spawn (spawning);
}
}
using UnityEngine;
using System.Collections;
public class MilitarySpawner : ItemSpawner {
public override void Init(){
addItem (ItemHandler.uzi);
addItem (ItemHandler.fireaxe);
addItem (ItemHandler.ump45);
}
}
Comment
Your answer
Follow this Question
Related Questions
UNet - How do I make Network.Spawn not show the prefab to the user that called it? 1 Answer
Why will the raycast not work on the client? 2 Answers
UnityScript not recognizing NetworkServer "Unknown Identifier" 0 Answers
Calling Command Function from Client results in "NetworkServer not active..." 1 Answer
UNET Server not setting [SyncVar] 0 Answers