1

I have a button under a canvas that is suppose to restart the scene. But instead its not calling the intended function of attached script.

On Unity Forums, I found solutions like it should be at higher hierarchy in canvas, and the canvas should have a graphic raycast and so-on.

But it still isn't working, although its on click array detects the intended method it is suppose to call.

Scene Editor with Canvas Selected:

2

Scene Editor with Button Selected:

1

11
  • Is the button registering a click at all? If not, then you'll probably have to show us the properties of your Canvas and Button so we can figure out if you've set up anything wrong. Commented Apr 7, 2016 at 16:08
  • How did you set this up? Did you add a new OnClick event (with the +) on the button? Did you drag the gameobject that has the script with the desired function into the slot and then pick the correct function from the drop down? Commented Apr 7, 2016 at 16:08
  • I clicked the + icon for onclick list and then it opened three slots, one of them was intended to hold the object with script, another one was to select the intended function from dropdown Commented Apr 7, 2016 at 16:14
  • I was trying to add screen shots, but SO won't let me...something about rep points. I have canvas with a canvas group(interactable = true), its graphic raycast(ignore reverse graph. = true) Commented Apr 7, 2016 at 16:16
  • My Button properties: interactable = true Commented Apr 7, 2016 at 16:21

3 Answers 3

4
  1. Remove the canvas component from your button.
  2. Make sure that there is a GraphicRaycaster on your canvas, and that there is an EventSystem object somewhere in the hierarchy.

(Both should have been added when you first added the canvas, but things get lost)

Sign up to request clarification or add additional context in comments.

1 Comment

I just looked at your images, remove the canvas component from your button object!
0

The screenshot that shows your button being selected, also shows, that you did pick a gameobject for the OnClick event, but you didn't pick a function from the drop down right next to that field, it says no function.

5 Comments

Also, only tick the answer as correct that solved your problem (or, if multiple, the best one). Joe Blow was a little drunk writing that ;)
@Gunner, I might have posted the wrong screen shot but the problem is, the button is not getting pressed/click in the first place. So even after I make sure there is method selected in the dropdown, it isn't working. :|
Does the button change color on hover and click?
No...that's what said before...I have used different colors for different states..the button is not disabled but its not getting highlighted or clicked...
If there is no highlighting, then something is blocking the button (= is in front of it).
0

Instead of selecting the C# class, select the GameObject that btnSceneSelect is attached to.

If btnSceneSelect is not attached to a GameObject, attach it to one (other than the button).

Taken from this site

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.