Hi, I am a unity beginner and I’ve made a score counter code, here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public int score;
public UnityEngine.UI.Text ThisIsTheScore;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void addScore()
{
score ++ ;
ThisIsTheScore.text = "Score: " + score;
}
private void OnTriggerEnter2D(Collider2D other)
{
addScore();
}
}
But, when I try to link the text in the unity editor from the hierarchy to the script, it just doesn’t let me:
What am I doing wrong here? I have tried everything…