Search Unity

Simple JavaScript btn Question

Discussion in 'UGUI & TextMesh Pro' started by rimawi, Sep 1, 2014.

  1. rimawi

    rimawi

    Joined:
    Mar 5, 2011
    Posts:
    34
    Hello,

    I want to check if my button was clicked and its tag is "correct" or ''not assigned"

    so where do i start:

    do i put my function on the button ( I have 4 of them one will be "correct" an the other 3 are "unassigned"

    and how do you write it.

    // I tried:

    Code (JavaScript):
    1. function Onclick(){
    2. if(this.tag=="correct"){
    3. Debug.Log(" I am the correctone");
    4. }
    5. else {
    6. Debug.Log(" I am the NOT correctone");
    7. }
    nothing happens.

    Thanks
     
  2. rimawi

    rimawi

    Joined:
    Mar 5, 2011
    Posts:
    34
    the solution was:

    Code (JavaScript):
    1. var mybtn:UI.Button;
    2.    
    3. function Start(){
    4. mybtn.onClick.AddListener(printS);
    5. }
    6.  
    7. function printS(){
    8.  
    9. if(this.tag=="correctanswer")
    10. {
    11. Debug.Log("I am correct");
    12. }
    13. else{
    14. Debug.Log("not correct");
    15. }
    16. }
    thanks