Button disabled when game starts

I’m trying press a button every time I want to start a minigame. In the minigame, it spawns random prefab fruits (up to 10) every second. Here is the code:

public float tiempoRespawn = 1.0f;
private Vector2 limitesPantalla;
public Button botonJugar;
void Start()
{
     limitesPantalla = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
     botonJugar.onClick.AddListener(ButtonJugarClicked);
}
void ButtonJugarClicked()
{
     StartCoroutine(frutas());
}
private void spawn(){
     GameObject f = Instantiate(frutaPrefab[Random.Range(0, frutaPrefab.Length)]) as GameObject;
     f.transform.position = new Vector2(-limitesPantalla.x * -2, Random.Range(-limitesPantalla.y, limitesPantalla.y));
}
IEnumerator frutas()
{
     for (int i = 0; i <= 10; i++)
     {
         yield return new WaitForSeconds(tiempoRespawn);
         spawn();
     }
}

I dont’ know why, when I start the game, the button is disabled and I can’t press it. I have tried to write botonJugar.interactable = true, but that doesn’t solve the problem.

If you drop a button on brand new scene in a new project to compare, does it work? Start there

Yes, I have tried it in a new project and scene and the button is enabled, I don’t know why it isn’t working in my project.

How are you debugging? https://discussions.unity.com/t/748729/14

Never mind, it was my fault. I didn’t remember that I was using the button for another thing which I forgot to change. Thank you for your time.

It’s typically proper forum etiquette to post your solution so others may benefit.

Yes, but the solution was that I was disabling that button with other script, I have only deleted that and now it works.

1 Like

So now you know how to debug, so it was a good thing!

1 Like