I am making the control panel for my game. At the bottom of the screen, there will be various textures to do various tasks: put you into combat mode, various attack types, camp outside a city, open your quest journal, etc.
I got one item working, but I’m unsure to make it work with multiple onMouseDown events. I would assume, you add a listener, but I thought you added it to onMouseEnter and Exit to add and remove.
Do you have a separate bool for each item and see if it was clicked?
Any help would be appreciated.
Thanks!
Are you using OnGUI or GUITexture?
If you are using OnGUI, use the builtin button with a style for the image(you can have separate images for hover, active, normal) see
GUI Style.
if(GUI.Button(rect,"Quest Journal",journalStyle))
{
Debug.Log("Clicked quest journal");
}
If you are using GUITextures there is a built in function called HitTest() that make it act like a button. Check out
GUIElement.HitTest.
if(guiTexture1.HitTest(Input.mousePosition,Camera.main))
{
Debug.Log("Clicked gui texture 1");
}
I suggest not using OnMouseEnter/Exit functions as they are intensive(those dont work on Phones either, for that reason).
I’d use GUI.Buttons if I were you. You can easily assign a texture to the button and what it does when you click it.
var AwesomeTexture : Texture;
var AnotherOne : Texture;
function OnGUI(){
if (GUI.Button(Rect(10,10,50,50),AwesomeTexture)){
//Do whatever
}
if (GUI.Button(Rect(20,500,100,100),AnotherOne)){
//Do something else
}
}