Score increase on button click?

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

public class playerController : MonoBehaviour {

public float speed = 20;
public Text countText;
private int count;
private bool isPressed = false;
 
void Start()
{
	count = 0;
	countText.text = "Score:  " + count.ToString ();
}

void Update() 
{
	var move = new Vector3 (Input.GetAxis ("Horizontal"), 0, 0);
	transform.position += move * speed * Time.deltaTime;
}

void OnCollisionEnter(Collision col) {
	
	if (col.gameObject.name == "crate1") {
		 Destroy(col.gameObject);
	}

}

void OnTriggerEnter2D(Collider2D other) 
{
	if (this.isPressed = false)
	{
		other.gameObject.SetActive(false);
		count = count + 1;
	}
}

}

I have this code right here. When ever I click a button called “YES”, I want the score to increase by 1, but I don’t know how to implement it into my code. How can I do it?

Add a collider to your gameobject (like a cube or something) and try adding this function to your class:

void OnMouseUp()
{
     score++;
}

If you want to add 1+ score pressing a Button you should try this:

void OnGUI ()
{
if(GUI.Button(new Rect(10, 10, 150, 100), “Yes”))
{
count++;
}

}

I hope this will work forma you.

Try using Event System then adding Event trigger on a UI button press, calling public method to call a button’s OnClick().

public void ScoreManager()
{
     score++;
}

I’ve no clue why, void OnMouseUp() or void OnMouseDown() is not working in your context, it should’ve worked like a cake, when you have a object with collider attached with it. Anyway hope you find help with event trigger with the UI, adding components accordingly.