Unity Button doesn’t accept function

I have this problem. I wrote a script with a method when interacting with which the player exits the game, but when I wanted to bind it to the button, and I realised that it didn’t work . In the OnClick() component, I attached my script, but for some reason the method is not attached.How can I attach my method?

enter image description here

Upvotes: 0

Views: 138

Answers (1)

Rajas
Rajas

Reputation: 338

Create an empty GameObject, attach your credits.cs to it then assign this gameobject to the OnClick(), then Credits > (Your method).

Make sure your method is public.

Upvotes: 1

Related Questions