I'm fairly new to Unity, and very new to networking concepts. I'm trying to attach a NetworkManager script containing a custom OnServerAddPlayer function to an empty game object with a NetworkManager game component. However, when I attempt to do this, I receive a "the script class cannot be found... ...ensure the file name and script class match" error.
My research has suggested vaguely that perhaps only MonoBehaviour scripts can be attached to GameObjects (?), but I haven't been able to find anything explicitly stating this anywhere. And if one can't attach NetworkManager scripts to GameObjects, how would one reference variables on the NetworkManager component like startPositions and spawnPrefabs? And does the script need to be attached to a GameObject for public override OnServerAddPlayer (NetworkConnection conn, short playerControllerId) {...} to be called?
Thank you in advance!
Edit: Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
class PlayerManager : NetworkManager {
int roundRobin = 0;
public GameObject newPlayerParent;
NetworkManager manager;
public override void OnServerAddPlayer (NetworkConnection conn, short playerControllerId) {
manager = gameObject.GetComponent<NetworkManager>();
Transform positionObject = manager.startPositions [roundRobin];
GameObject newPlayer = GameObject.Instantiate(manager.spawnPrefabs[roundRobin], positionObject.position, positionObject.rotation, newPlayerParent.transform);
}
}
I am trying to attach the script by dragging it from the project view onto the inspector for an empty object with the NetworkManager, NetworkManagerHUD, and NetworkDiscovery components attached.