Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using TMPro;
- public class Scorer : MonoBehaviour
- {
- int hits = -1;
- public TMP_Text hitCounterText;
- void Start()
- {
- if (hitCounterText != null)
- {
- hitCounterText.text = "Hits: 0";
- }
- else
- {
- Debug.LogWarning("HitCounterText is not assigned in the Inspector!");
- }
- }
- private void OnCollisionEnter(Collision other)
- {
- if (other.gameObject.tag != "Hit")
- {
- hits++;
- Debug.Log("You have crashed this many times: " + hits);
- if (hitCounterText != null)
- {
- hitCounterText.text = "Hits: " + hits;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement