- Home /
How to call array element that has bool value true
I have four buttons using the same prefab and holding 4 text elements from an array out of which only one is assigned bool value to true. I am trying to access that true element when any of false element is clicked. i want to highlight true element when the false element is clicked. can anyone please help me to achieve this functionality? Thanks
  public void HandleClick()
     {
         gameController.AnswerButtonClicked(answerData.isCorrect);
         {
             if (answerData.isCorrect)
             {
                 StartCoroutine(ReturnCorrectButtonColor());
             }
 
             if (!answerData.isCorrect)
             {
                 StartCoroutine(ReturnWrongButtonColor());
                 
             }
  
     }
  
                 
Answer by LAZYGAMES_ · Aug 22, 2018 at 02:28 PM
 public GameObject[] buttons;
 
 public void HandleClick()
          {
              gameController.AnswerButtonClicked(answerData.isCorrect);
              buttons = GameObject.FindGameObjectsWithTag("Answerbttn");
              {
                  if (answerData.isCorrect)
                  {
                      StartCoroutine(ReturnCorrectButtonColor());
                  }
      
                  if (!answerData.isCorrect)
                  {
                      StartCoroutine(ReturnWrongButtonColor());
 
                      foreach (GameObject button in buttons)
                      {
                            if(button.GetComponent<NAMEOFSCRIPT>().answerData.isCorrect)
                            {
                                   button.GetComponent<NAMEOFSCRIPT().StartCoroutine(ReturnCorrectButtonColor());
                            }
                      }
                  }
       
          }
Tag all four buttons with Answerbttn (or something else if you change it in the script) 
 Hope that helps:)
@Sh4d0w08 thank you for your help. I tried above code but it is changing wrong answer button to green ins$$anonymous$$d of highlighting correct answer button at the same time.
Sorry my mistake -.- 
change 
 button.GetComponent<NA$$anonymous$$EOFSCRIPT().StartCoroutine(ReturnCorrectButtonColor());
 to:
 StartCoroutine(button.GetComponent().ReturnCorrectButtonColor(0));
 and make sure your Coroutines are public
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                