Creating a global function, callable from anywhere

I’m making a first person game, and want to create pickup objects for the player to collect.

Ideally, I would be able to call something like:

PickupManager.CreatePickup(PickupType.ROCK, transform.position);

Also, I’d like to specify the prefabs to create by dragging prefabs onto the manager script variables via the inspector.

It seems if I create a static class, then I can’t specify prefab types via the inspector (because the vars are static and not exposed).

If I create a singleton with a GetInstance() function, the instance doesn’t seem to inherit the vars I assign via the inspector.

Should I be using a static class? A singleton? Do I need to attach a script to a gameobject?

If you want to drag’n’drop prefabs on it in the Inspector you have to attach it to a GameObject.

You could handle this by simply only having one GameObject with the script on it in the scene, with the script containing something like this:

private static var instance : PickupManager;

function Awake() {
    if (instance) {
        Debug.LogError("More than one instance.");
    }
    instance = this;
}

static function GetInstance() : PickupManager {
    return instance;
}

… which could then get properties for prefabs etc. and would be used like this:

PickupManager.GetInstance().CreatePickup(PickupType.ROCK, transform.position);