Hey there,
Problem: I have an Transform array of chairs, each one can be empty or occupied.
I think extending Monobehaviour would be a little overhead.
So is there a way to attach a script to a GameObject that is not extending Monobehaviour (or ScriptableObject).
And is ScriptableObject a choise for such a problem?
Edit: I just noticed that when I add a “ScriptableObject-Script” to one chair, you are not allowed to add it to another chair, so this way it would not work either.
Thanks in advance!
I don’t think extending MonoB is that big a deal. I assume you mean you need a small data script:
class chairData : MonoBehaivoir {
public bool Occupied;
}
I think the engine merely adds all of your Updates, OnCollisionEnters … to a list. I don’t think
that every frame it loops through every chair object, looking for a nonexistant Update.
But if you really want it lightweight, just don’t put the class on the object. If you have 20 chairs, store the list of 20 occupied vars in an array, elsewhere:
// some "master" script, which can also hold chair data:
class playerScript : MonoB {
class chairData {
public Transform chairT;
public bool Occupied;
}
chairData_t[] Chairs;
...
At start, fill the Chairs array with a pointer to each actual chair. The drawback is there’s no good way to go from a real chair back to this. Like, if someone clicks on a chair, have to loop through the array, checking Chairs*.chairT==clickedOnChair. But that’s not really a problem.*
I’ve found I usually want to add OnCollision or some other MonoBehaiv function, or set Inspector vars by hand. So I usually end up rewriting these as MonoB scripts, anyway.