- Home /
 
Button.interactable not enabling
Trying to add a penalty when the player missed an enemy but I can't seem to be able to re-enable the buttons after disabling it for a few secs.
 void Update()
     {
 
         RayCastShow();
         
 
         frozenTimer -= Time.deltaTime;
 
         if (frozenTimer <= 0)
         {
             btnL.interactable = true;
             btnR.interactable = true;
             isFrozen = false;
         }
         
     }
 public void Miss()
     {
         frozenTimer = 1f;
 
 
         btnL.interactable = false;
         btnR.interactable = false;
         
 
     }
 
               Can someone please tell me what's wrong in my code thanks
               Comment
              
 
               
               public void RayCastShow()
     {
         int layer_mask = Layer$$anonymous$$ask.Get$$anonymous$$ask("Enemy");
 
         RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, -transform.right, 500, layer_mask);
 
 
         if (hitInfo.collider != null)
         {
             hitInfo.collider.gameObject.Send$$anonymous$$essage("Hurt", Send$$anonymous$$essageOptions.RequireReceiver);
             print(hitInfo.collider.gameObject.name);
             Debug.DrawLine(transform.position, hitInfo.point, Color.red);
         }
         else
         {
             Debug.DrawLine(transform.position, transform.position + -transform.right * 500, Color.green);
             $$anonymous$$iss();
 
     
         }
     }
                  I think you should not be calling RayCastShow() in the Update function. Is it a 2D shooting game, if so you can call RayCastShow() when the user presses the fire button.
Answer by Jinnie26 · Jan 09, 2018 at 01:58 PM
Found a fix!! Instead of using the frozen timer, since I was disabling the buttons I used those as the condition and use the Coroutine to make the buttons interactable again
 if (btnL.interactable == false)
         {
             StartCoroutine(btnInteractable());
         }
 IEnumerator btnInteractable()
     {
         yield return new WaitForSecondsRealtime(1f);
         btnL.interactable = true;
         btnR.interactable = true;
         Debug.Log("Working Dapat");
         
     }
 
              Your answer
 
             Follow this Question
Related Questions
[C#] Both button check with delay. 1 Answer
Scene not loading properly on android device? 0 Answers
Unity 5 GUI system 1 Answer