can you assign gui elements to layers?

That way when I ignore specific elements on raycast, I can account for the GUI as well.

There is no way, at this time(3.4 and below), to create groups of gui elements that exist on a layer in the same way that you can create layers in the World.

But you can achieve the same sort of thing with clever use of the following information:

Event.current.Use and GUI.depth

Within OnGUI call you can catch mouse events and prevent them from going to GUI elements that are behind it. So if you have a Window element floating over some buttons, you can call Event.current.Use at the end of the Windows display function to prevent the mouse event from reaching buttons behind the window.

GUI.depth exists to allow you to specify the sort order of all OnGUIs. So lets say yo have three OnGUI() in your scene. Each OnGUI
can be at a specified depth. Within an individual OnGUI, you can only control what draws ontop of what by the order that the GUI calls appear where later calls draw before earlier calls. If you set GUI.depth multiple times within on OnGUI only the last one takes effect. So thats OnGUI layer sorting for you.

you can do it this way :

static var layer : int = 1;

function OnGUI (){

if (GUI.Button(Rect(10,70,50,30),“Click”)){

if (layer == 1){

layer = 2;}

else{

layer = 1;
}

}

if (layer == 1){

GUI.Label (Rect (10, 10, 100, 20), "Hello!");

}

if (layer ==2 ){

GUI.Label (Rect (10, 10, 100, 20), "World!");

}

}

//other script

if (LayerController.layer == 1) {

gui.physics.ignoreRaycast = true;
}

this lets you toggle the gui layer at will.

What I like even more with this system is you can do it this way too :

1st script:

static var guiLayer : int = 1;

2nd script:

if (1stScript.guiLayer == 1){
do layer 1 gui stuff here.
}

3rd script :

if (1stScript.guiLayer == 2){
do layer 2 gui stuff here.
}