This problem is giving me headaches and is taking a while to figure out, can you guys help me out. I posted a related problem a few days ago that worked, but only for making objects inactive. Now that they are inactive, whenever I try to use the GameObject.FindGameObjectsWithTag() function, it cannot find the inactive gameobjects.
Here's my code:
I've messed around with it quite a bit, so sorry for all the comments, and weird stuff in the start function.
Thanks for any help!
What you need to do is maintain a list of inactive objects so you don't need to use find with tag all the time which is what your problem is.
When you deactivate them do something like this:
Then when you want to bring them back on do this:
answered Jul 01 '10 at 02:12 PM
Another approach would be to selectively disable the components that a gameObject have, instead of disabling the gameObject. This approach lets you access again the gameObject via the methods you mentioned:
Suppose that you have a gameObject with a Mesh Renderer and a script called myScript. You can set those two object to a disabled state:
Colliders are more tricky. You can disable them by setting the gameObject in a different layer eg 10.
You should then define in the Physics inspector that objects in layer 10 don't collide with other objects. Physics inspector can be found in Menu->Edit->ProjectSettings->Physics and the place you define the collisions is the Layer Collision Matrix.
Notice that for perfomance reasons it seems to be a good practice to disable all scripts that contain onGui functions when you don't use them.
A good explanation on why you should do this is here http://www.mindthecube.com/blog/2010/09/avoiding-performance-cost-of-ongui
(since scripts are MonoBehaviours that descent from Behaviours so they inherit their variables)