do i need the image component for clicking on the button to work? i thought i had a button working without it, but now my buttons aren’t working with only the text element and the image component removed.
edit: okay, i added in image components but i’m still not getting the buttons to work. it’s hard to tell because Unity doesn’t respond to my code in the same way all the time. for example, sometimes it will show inventory icons, sometimes it won’t, like not all the scripts are being interpreted fully all the time. will building the game fix this?
edit2: here’s some code. i don’t know why my buttons aren’t working.
public void ExamineButton()
{
InvRCMenu.enabled = false;
// create examine gui
// set text to inventory[i].description;
ExamineCanvas.enabled = true;
examinemove.transform.position = theText2.transform.position + new Vector3(5, 80, 0);
// DEBUG: not finding the inventory
examinetitletext.text = inv3.inventory[Globals.invindex].item.objname;
examinetext.text = inv3.inventory[Globals.invindex].item.description;
}
my menu with it’s four buttons used to work, but then i changed some code and it stopped working. now i rechecked my code and made sure i dragged in the references, but i can’t get any of the butttons to work.
edit3: okay, i restarted Unity. i finally got one of the buttons to work after clicking on it several times, but was unable to repeat this feat. i’m checking out google to see if i can find anything.
could having a IPointerClickHandler on the same button text interfere with the button? if so, that kind of sucks as i need to have both working.
edit: i started up Unity and VS again. sometimes if i click on a tiny portion of the button it will work but it’s very hard to do. what could be going on?
i re-added the image component which seems to register a click when i click on the button, but the code only executes a small fraction of the time, as i described above.
I dealt with this to have a single large button over a board game I was making.
This was the reference I used:
It seemed to work pretty well, a “NonDrawingGraphic” as described in that link above. I just used an EventTrigger object to grab the up and the down events and then did other processing separately.
i am fine with having an image component. i re-added image components to the buttons and they helpfully grey out the space when i click it. i just can’t figure out why my buttons are misbehaving.
does this help? i tried to make a small sample project but i have so many references i’d practically have to upload the entire thing. i can show code too if you ask.
i noticed i have buttons in another scene that DO work, and the canvas for them is set to world space, whereas the not-working buttons’ canvas is set to screen space - overlay. i tried setting it to world space instead, but then i couldn’t get my menu with the buttons to even appear, and besides that all of my canvases in this scene are set to screen space.
i figured it out! the text was getting in the way of pressing the button. any ideas how to solve this, as i do need these buttons to have text on them?
edit: okay, i changed the image highlight color, which works well enough for my purposes. i would prefer to change the text color, but disabling raycast on the text also disables it for the interfaces i use for changing the text color. if anybody knows how to make it so i can just change the text color from black to red and still have the button work, i’m all ears.
edit2: so does this mean that the IPointer interfaces work by raycasting as well?
I didn’t look at your project since your update says you mostly figured it out. I’m pretty sure the interfaces work with raycasting. You’ll notice that if you do not have the appropriate raycaster, things won’t work (UI, 2d, 3d versions, for instance)…