Hello Guest

Author Topic: Detect mouse hover on GUI/Tileset  (Read 4677 times)

kabuto202

  • Newbie
  • *
  • Posts: 6
    • View Profile
Detect mouse hover on GUI/Tileset
« on: February 07, 2014, 09:15:59 pm »
So I've been struggling with finding a decent method of doing this since last, I started out with Unity's GUI system and eventually moved on to the one here hoping for more functionality, but I'm struggling with the script references to find what I need.

So in short, say I have a tileMapA, a GUILayoutA(Containing ButtonA, ButtonB, and ButtonC), and a MasterControl GameObject, and a bunch of whitespace in between. When the player clicks on tileMap functionA gets called from MasterControl, when the player clicks on a GUILayout OR in the whitespace, nothing gets called, and when the player clicks on the Buttons A, B, and C, function A, B, and C, get called respectively.

What's the most efficient way of going about this?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Detect mouse hover on GUI/Tileset
« Reply #1 on: February 07, 2014, 11:01:43 pm »
If you use tk2d UI, then you will have a "panel" with buttons on it. By panel I mean a background object with a collider that blocks ray casts into the background. Use the event system to bind button presses to functions (the UI samples demonstrate how you can do this). You can do all this in the interface.

You can then treat the entire tile map as a huge invisible button behind the above should you choose to. tk2d UI uses the collider to track presses so all you need is a large-thin box collider behind the above with a tk2dUI event attached. You can then hook into the event to call functionA.

In case it isn't obvious - You can link up functions to button presses either using the event binding in c# (.OnClick += ...) or dropping visually using the "SendMessage" functionality. The samples do a mix of both as appropriate.