Evan Welch
Evan Welch

Reputation: 15

Unity C# Button On Panel Not Working Putting Script On The Button

I'm sure that I am tangled in my own code so it would be easy I bet to help me out of it I would really appreciate someone throwing me a line.

Can you attached a script to a button and then call a method in that script using that button's onClick in the unity inspector?

Upvotes: 1

Views: 540

Answers (1)

lrainey6-eng
lrainey6-eng

Reputation: 223

just so you know, you create a specific 'button' in unity, not a GameObject with a sprite, so that it has a built in unity function where you write a very short piece of code:

public void FunctionName()
{
    Do(what_youWant.here)
}

and put the script on the actual button, then have a look at the button's components list, and you'll see a place for functions; there you select (from the dropdown) your function from the code.

Upvotes: 1

Related Questions