Unity 3D Game Dev Day 4: How to make a score system using onCollisionenter and make it show on the canvas?
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class ScoreChanger : MonoBehaviour
{
int hits = 0;
[SerializeField] private TextMeshProUGUI scoreText;
private void Start()
{
UpdateScoreText();
}
private void OnCollisionEnter(Collision other)
{
hits++;
UpdateScoreText();
}
void UpdateScoreText()
{
scoreText.text = hits.ToString();
}
}
Then drag the TextMeshPro Text here , you can change the score.