4.6 New GUI Questions

So i’ve been messing around with the new GUI tools in 4.6. and I currently have two questions. (i’m sure ill have more soon.)

I have a world space Canvas (myCanvas) that I’m trying to detect whether or not the mouse is hovering over. The canvases have a RectTransform component which allows me to access their ‘rect’ property and then the ‘Contains’ function, but it doesnt seem to work. anyone have an idea why this may be?

void Update() {
  mouse = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
  myCanvas.rect.Contains (mouse);
}

The other question is about the Graphic Raycaster component on the new GUI elements. There doesnt seem to be any documentation on them yet. Anyone have an idea what to use them for?

thanks!!

I think you can most cleanly do this using the new event handling system. I don’t yet understand the raycasters either, but Event Triggers are now components, and I think that an Event Trigger is all you need for the functionality you describe.

Try this:

Go into the inspector panel for your Canvas, click Add Component → Event → Event Trigger. Then on the new Event Trigger component click Add New → PointerEnter. You can then set the parameters on the PointerEnter field so that it calls any public function you like. You can also enter a single argument that will be passed to that function. Next time the pointer enters the Canvas, the Event Trigger component will call the given function with the given argument. If you like, you can add any number of function calls to a single Event Trigger, and you can add any number of Event Triggers to a GameObject.

The Events tutorial goes over this in a little more detail:

http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-events-and-event-triggers

The Graphics Raycaster is used for input; If you want a canvas and it’s content to accept input, you need to have this attached to the canvas.