c# - Button `OnSelect` not functioning in Unity.UI Canvas situation -


i have 3 buttons, when tap 1 button, panel text appear.

the problem when attached script, nothing happens. "click" registered the panel never appears.

my script attached each of button , this:

public gameobject panel; //i use put panel in unity bool selected = false;  void start () {         panel.setactive(false);  }  void onselect() {         selected = !selected;     panel.setactive(true); } 

i have else panel can't figure out.

do this:

(1) add canvas project

(2) big tip - sure select scale screen size.

that's 1 ever use. unity accidentally set wrong default there, have not fixed yet.

(3) in canvas, add button make perhaps "test"

(3) in canvas, add button make perhaps "another test"

(4) make script this...

public class mainscreen:monobehaviour     {     public void userclickedtest()         {         debug.log("test..");         }     public void userclickedanothertest()         {         debug.log("another test..");         }     } 

(5) put 1 copy of script on object like. can put on camera, on canvas, or anywhere else makes sense

for let's put on camera object, example.

(6) click on button "test" .....

enter image description here

and ...

  1. click plus button under onclick

  2. you see slot says "_main" in example. drag camera item heirarchy, slot

  3. using drop down menu:

select "userclickedtest()" function ...

good eh?

  1. now other button, same select "userclickedanothertest()" function.

  2. you're done! run , test!

you can't use onselect system unless use iselecthandler , more stuff: difficult beginners. recommend op masters simpler technique explain here. enjoy!


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -