I am trying to make a score system for each time when a sprite hits its corresponding sprite though whatever I do it will never work
public class script : MonoBehaviour
{
public float speed;
private float score;
private void Start()
{
score = 0;
Updatescore();
}
private void Update()
{
transform.Translate(Vector2.left * speed * Time.deltaTime);
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag ("Player"))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
if (other.tag == gameObject.tag)
{
Destroy(other.gameObject);
Destroy(gameObject);
score += 1;
Updatescore();
}
else
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
private void Updatescore()
{
Text txt = transform.Find("score").GetComponent<Text>();
txt.text = score.ToString();
}