- Home /
Specify OnMouseEnter
I have a game where the player can purchase upgrades for himself from a in game 'shop'. I wanted to have the code for the entire shop within 1 script.
Unfortunately as soon as I started i found out that the code =
function OnMouseEnter () {}
Will only peform for the object it is attached to. For instance I am not allowed to do something like this =
var button1 :GUITexture;
var button2 :GUITexture;
function OnMouseEnter (button1) {}
function onMouseEnter (button2) {}
Which is really annoying, so if anyone can tell me otherwise I would be really appreciative.
Answer by Statement · Mar 27, 2012 at 02:53 PM
Attach the script to each GUITexture that in turn call back to your shop, like shop.SendMessage("OnMouseEnterGUITexture", guiTexture)
, or Raycast to find out which GUITexture is under your cursor. This way you can do it all in one central script.
Thanks for the answer, was really just checking so see if the function could be made specific. It's a little too much effort for a Raycast, good thought though. Ill just attach the script to each button.
Answer by moichezmoi · Mar 27, 2012 at 05:26 PM
Another way would be to use the OnGUI() method, as described here.