Search Unity

Selection Issues

Discussion in 'Scripting' started by shawnpigott, May 23, 2011.

  1. shawnpigott

    shawnpigott

    Joined:
    Sep 28, 2005
    Posts:
    262
    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):
    1. function SetIcons () {
    2.     var AllIcons : BoxCollider[] = FindObjectsOfType(BoxCollider) as BoxCollider[];
    3.     for (var IconType : BoxCollider in AllIcons) {
    4.         if (IconType.gameObject.GetComponent.<MainMenuTapToGo>().whichIcon != WhichIconSet){
    5.             IconType.gameObject.renderer.enabled = false;
    6.         }
    7.         else{
    8.             IconType.gameObject.renderer.enabled = true;
    9.         }
    10.     }
    11. }
     
  2. BlackGecko

    BlackGecko

    Joined:
    Mar 25, 2011
    Posts:
    10
  3. callahan.44

    callahan.44

    Joined:
    Jan 9, 2010
    Posts:
    694
    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.
     
  4. shawnpigott

    shawnpigott

    Joined:
    Sep 28, 2005
    Posts:
    262
    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.