I have a map with 4 different types of icons on it. On the top of the map there are buttons which allow you to choose which icon is displayed. I've written a script that stops rendering the non-chosen icons but they are still selectable as their colliders are still active. I tried disabling the whole Game Object but then I couldn't turn them back on. As far as I know, you can't turn on and off a collider so I'm a bit stumped. Any suggestions? Code (csharp): function SetIcons () { var AllIcons : BoxCollider[] = FindObjectsOfType(BoxCollider) as BoxCollider[]; for (var IconType : BoxCollider in AllIcons) { if (IconType.gameObject.GetComponent.<MainMenuTapToGo>().whichIcon != WhichIconSet){ IconType.gameObject.renderer.enabled = false; } else{ IconType.gameObject.renderer.enabled = true; } } }
The worst possibility you have is to destroy the collider and recreate it. Does this help? http://unity3d.com/support/documentation/ScriptReference/Collider-isTrigger.html
Keep a reference to the GameObject so you can turn it on/off, avoiding the Find methods that are slow and don't return inactive GameObjects. If you only want to disable Colliders you use Physics.IgnoreCollision.
Thanks for the suggestions. I probably should have mentioned that this script is for an iPhone. I was hoping that there might be a simple way to filter which information was displayed on the map so that it was possible to then select a specific item. Using the above script, destroying the collider would result in the object being removed from the search criteria. I could probably search by script instead though. An array of the objects would probably be the most efficient. Are there find methods which return inactive objects? I was thinking that I could possibly just shrink the size of the collider so that it's effectively off. Thanks again.