Hi,
I am working on a linear jump n run type game. I have split it up into sections so that each section is basically a gameobject with several children. Each section is self-contained and should not be computed until it is needed and should be destroyed afterwards.
Very importantly, I have a static list of objects. When an object awakens, it adds itself to the list. OnDestroy, it removes itself. Objects of this class are computationally most intensive. This static class is called allAttract.
Ideally, onCollisionEnter of my gameobject for a certain section, I want all instances of allAttract to be awakened (i.e. added to my static list). onCollisionExit I want all of them to be destroyed (i.e. removed from the list). This should keep my framerate high.
Let is say I am entering a section. I collide with a gameobject called bouncePuzzle. It contains all sorts of things as children, including allAttract objects. I guess I would like a script which is called onCollisionEnter. It would basically loop through all children, filter allAttract by tag and awaken them.
I would want another script which is called onCollisionExit. It would also loop through all children, filter allAttract and destroy each of them. The static geometry would remain as it doesn’t do much.
Two things here:
- Does my reasoning make sense to you or is all of this a bad / inefficient idea?
- If I’m doing OK, how can I loop through all children and (after having filtered by tag) awaken / destroy objects?