|
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!
(comments are locked)
|
|
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:
Array docs: http://unity3d.com/support/documentation/ScriptReference/Array.html Yes that works perfectly! Thank you!
Jul 01 '10 at 03:04 PM
Fusobotic
Glad I could help
Jul 01 '10 at 07:34 PM
spinaljack
(comments are locked)
|
|
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 References: http://unity3d.com/support/documentation/ScriptReference/GameObject-layer.html http://unity3d.com/support/documentation/ScriptReference/GameObject.GetComponent.html http://unity3d.com/support/documentation/ScriptReference/Behaviour-enabled.html?from=MonoBehaviour (since scripts are MonoBehaviours that descent from Behaviours so they inherit their variables) http://unity3d.com/support/documentation/ScriptReference/Renderer-enabled.html I'm having trouble defining the collision parameters for a specific layer (layer 10 in your example) to turn off collisions... Could you elaborate?
Apr 07 '12 at 03:39 PM
valichm
(comments are locked)
|
