UI button is not working

As the title says, I can’t do anything to make it work:(.If I press the button,I want it to add 1 to the total number of currentprogr, but to later use the variable.Now, it shows the changeble text, but the button doesn’t find any function in the class Hire_programmers or GameMechanics or Employees.I even assigned both scripts to the button.:frowning:

.
Here is my code:
The main c#:

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

public class Employees
{
    public static int currentprogr=0;
}
public class GameMechanics : MonoBehaviour {
    GameObject currentpr;
    Text curprogr;
    void Start{
    myTextgameObject = GameObject.Find("Datetext");
    currentpr = GameObject.Find("currentprogr");
    }
    void FixedUpdate{
        curprogr = currentpr.GetComponent<Text>();
        curprogr.text = "Current programmers:"+Employees.currentprogr;
     }
}

The button code:

using UnityEngine;
using System.Collections;

public class Hire_programmers : MonoBehaviour {
     void OnMouseDown()
    {
            Employees.currentprogr++;
    }

}

Thank you in advance for your cooperation. Peace!:):slight_smile:

You don"t need to use code for your button. Just make a function in your gameMechanics like this:

public  void IncrementProg()
    {
            Employees.currentprogr++;
    }

and then in the inspector of the button you’ll find the OnClick callback, click on the little “+” to add a callback, select your GameMechanics object and your IncrementProg function (don’t forget to make it public as below) and then it will be called on each click of the button.

You can see the onclick at the bottom of the button component:
2747266--198081--upload_2016-8-10_16-25-53.png

Thanks! I have found the mistake. My function was only “void” and not “public void”. Thanks a lot!