So I am making this simple game where the player has to click on all the squares until there are no squares left on the screen. The score board should tally how many squares have been collected. When all the squares have been collected, an end menu appears.
This is the score script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Score : MonoBehaviour
{
public Text scoreText;
public int score;
void Start()
{
//score = GetComponent<Text>();
}
void Update()
{
scoreText.text = "Score: " + score;
if(Input.GetMouseButtonDown(0))
{
score++;
}
if (score >= 6)
{
SceneManager.LoadScene("end menu");
}
}
}
And this is the destroy square script:`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Collect : MonoBehaviour {
GameObject Square;
void OnMouseDown()
{
Destroy(gameObject);
}
}
`
As you can see the score increases just with a mouse click, i only want the score to increase when i collect (and destroy) the square. How can I do this?