Quantcast
Channel: Unity Forum
Viewing all articles
Browse latest Browse all 1466670

Yield not working with onClick.AddListener.

$
0
0
Here is a strange behaviour that I found:

Code (JavaScript):
  1. function Start()
  2. {
  3.     button.GetComponent(UI.Button).onClick.AddListener( BtnFunction );
  4. }
  5.  
  6. function BtnFunction()
  7. {
  8.     print("test 1");
  9.     yield WaitForSeconds(1);
  10.     print("test 2");
  11. }

Neither "test 1" nor "test 2" will appear on the console, the code seems not to be executed. But, as a workaround, this would work:

Code (JavaScript):
  1. function Start()
  2. {
  3.     button.GetComponent(UI.Button).onClick.AddListener( Temp );
  4. }...
Yield not working with onClick.AddListener.

Viewing all articles
Browse latest Browse all 1466670

Trending Articles