Hiding GameObject from a button

So, i have this button, i want it to hide a GameObject when it is pressed. i’ve tried numerous codes and mixing and matching with no luck. I’m in no way a coder and this has me stumped… i’m sure it’s been answered elsewhere, i’ve searched high and low through various google searches and keep getting errors or only getting the button to disable. I know it’s pretty simple but i have no idea what i’m doing in general.

the name of the GameObject is ObjectChunk

private var ObjectChunk : GameObject[];

function OnMouseEnter(){
}

function OnMouseUp(){
ObjectChunk.gameObject.active = false;
}

this script is attached to a plane with a texture on it.
if any other info is needed let me know.

please and thank you!

And what error did you have?

Try this :

    private var ObjectChunk : GameObject[];

    function OnGUI(){
      if(Rect(10,10, 100, 30), "Hide")
         OnMouseUp();
    }     
     
    function OnMouseUp(){
      for(i : int = 0; i< ObjectChunk.Lenght; i++)
      {
         ObjectChunk[i].gameObject.SetActive(false);
      }
    }

UPDATE: You have an array of objects in the ObjectChunk variable, and if you want to change it you need to set the Index of object wich you want to change:

ObjectChunk[ IndexOfObject ].gameObject.active = false;

as simple as this is, why does this seem so complicated?
is there no specific way to find GameObject and just disable?

private var ObjectChunk : GameObject[];

 

function OnGUI(){
	if(Rect(10,10, 100, 30), "Hide")
		OnMouseUp();
}

function OnMouseUp(){
	for(i : int = 0; i< ObjectChunk.Lenght; i++)
	{
		ObjectChunk[i].gameObject.SetActive(false);
		}
	}

Also I must note, this is Unity Free version if that makes any difference as well.

and for ObjectChunk[ IndexOfObject ].gameObject.active = false;
what is the index of an object? how do i find out?

Using your code I’ve received 4 errors:

Assets/Standard Assets/test.js(6,32): BCE0044: expecting ), found ‘,’.
Assets/Standard Assets/test.js(6,34): BCE0043: Unexpected token: Hide.
Assets/Standard Assets/test.js(11,13): BCE0043: Unexpected token: i.
Assets/Standard Assets/test.js(11,52): BCE0043: Unexpected token: ).
Assets/Standard Assets/test.js(13,59): BCE0044: expecting :, found ‘;’.