Can't get onClick work

I’m trying to create on screen controls so I’ve added four buttons but they just won’t work. Here’s the screenshot of this situation:

I have a script

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

	public void testClick() {
		Debug.Log ("Click");
	}
}

When I press the ButtonUp nothing happens. The console is clear.
I’ve tried to create Buttons via Create>UI>Button but those buttons disappear when I run the game.

Looking at your project, youve simply set up the button incorrectly.

Right click Canvas. Select UI → Button.

You will see that this is how a button should look. Yours Button(1) does not seem to be a button at all.

The one you have set up uses PointerDown and also is looking at “Button” rather than “Button(1)”

Select Button(1) and implement IPointerDownHandler in your current setup, or delete your existing button and set up a new one as I have outlined.

When you set up a new one you will see it uses OnClick instead of PointerDown.

Make sure your UI related scripts use

//(uJS)

import UnityEngine.UI;
import UnityEngine.EventSystems;

If you want to use Pointer functionality :

public class YourScript extends MonoBehaviour implements IPointerDownHandler, IDragHandler, IPointerUpHandler
{
    function OnPointerDown(){}
    function OnDrag(){}
    function OnPointerUp(){}
}

If these interfaces are not implemented in the class setup the respective functions will not work in the EventSystem but will just become unrelated custom functions.

you see that big white line going through the middle of your level? that represents the bottom left corner of your UI canvas. zoom out and place the buttons in side of that to make them appear.

i also noticed that their is no event system, an important part of making any UI action work at all. creating a canvas or any UI element should automatically add one to the scene.

As I can see from you don’t have an event system in the hierarchy. Add one by clicking on GameObject → UI → EventSyste and run it again.
EventSystem is responsible for all user input so that’s the reason why your click isn’t caught.

Hi,

Add Event Trigger to Button instead of onclick().