Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

From a button to hide/unhide a mesh

Discussion in 'Scripting' started by yvesbodson, Sep 10, 2010.

  1. yvesbodson

    yvesbodson

    Joined:
    Jul 15, 2010
    Posts:
    64
    I have asked some times ago about that question but did not resolve it yet
    it maybe too easy to most of the members but simply I don't get the api to get that working
    so if someboy had an anwser thanks in advance
    here is the code
    The menus before are working fine
    ==========================================
    private void ButtonDiamondW_OnClick(object source, ClickEventArgs e)
    {


    component = GameObject.FindGameObjectsWithTag("perle_bagu");

    //print("This is component component[2]" ); // does not work too much red in the debugger

    //for(var j=0 ; j<component .length ; j++) {
    component [2].active = false;
    // does not work either so many entries in the debugger
    }


    =============================================
     
  2. Vimalakirti

    Vimalakirti

    Joined:
    Oct 12, 2009
    Posts:
    755
    You are not getting an answer because your question is vague. I see a few things going wrong here.

    1) using EventArgs did not work for me. For a messenger script I used the one at this link:

    http://www.unifycommunity.com/wiki/index.php?title=CSharpMessenger

    2) to make a button you want to use Unity's GUI features which you can look for here:

    http://unity3d.com/support/documentation/Components/GUI Scripting Guide.html


    3) To search through the objects in your scene by name, use something like this:
    Code (csharp):
    1.  
    2.     Transform SearchInScene(string myType)
    3.     {
    4.             // Go through all Objects in scene to find the ones of that name
    5.         GameObject[] GOs =  GameObject.FindObjectsOfType( typeof( GameObject ) ) as GameObject[];
    6.         Transform theOneFound = null;
    7.         foreach ( GameObject GO in GOs )
    8.         {
    9.                 if( GO.name == myType)
    10.                 {
    11.                 theOneFound = GO.transform;
    12.                 // Find mesh here and do what you want...
    13.                 }
    14.         }
    15.         if(theOneFound) return theOneFound;
    16.         else return null;
    17.     }
    18.    
     
  3. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Lol :)

    Can you post the declaration for 'component'? Also, are you sure the 'component' array has at least 3 elements?