Button Listener not detecting click?

Hey guys, I have made a script with the correct listeners and everything but it is not detecting the script? I ripped this out of another project that was working.

using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Collections.Generic; using System; using System.Collections;

public class PlanetSelect : MonoBehaviour {

[Serializable]
public class Planets
{
public GameObject Planet_Obj;
public string Planet_Name;
public int Planet_Number;
public Vector3 OffSet;
}

public Text PlanetNameText;
public List Planet = new List();

public int CurrentPlanetNumber = 0;

void Start () {

Camera.main.transform.position = Planet [CurrentPlanetNumber].OffSet;
CurrentPlanetNumber = 0;
}

void Update () {

Camera.main.transform.position = Planet [CurrentPlanetNumber].OffSet;
PlanetNameText.text = Planet[CurrentPlanetNumber].Planet_Name;

}

public void ButtonClick (bool Up)
{
if (Up) {
CurrentPlanetNumber++;
Debug.Log (CurrentPlanetNumber);
} else {
CurrentPlanetNumber–;
}
}
}

![2909923--214521--upload_2017-1-6_13-59-57.png|555x774](upload://4IcHmHpnVyJpeShp1CW9h7zLUHX.png)

So the debug message doesn’t print?

If the button isn’t registering your button click, you might have an invisible UI object(maybe an image with 0 alpha, or an image with it’s own alpha channel) with the RaytraceTarget boolean switched on, and therefore blocking your button.

to test this, make this button object the very last item under canvas, and see if you are able to detect the button click.

Found the error I made, I didn’t add an EventSystem, simple mistake my bad.

2 Likes

Probably the most common reason for the UI to not respond to clicks. Glad you got it sorted.