So i know this is a common problem but the solutions ive seen are not working for me, Sorry if i havent given enough information. Line 31 is where the error happens according to unity. Here is the code
using UnityEngine;
using UnityEngine.UI;
public class Scoring : MonoBehaviour
public Text Score1;
private int scorePoint1;
// Update is called once per frame
void Start()
{
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.name == ("WallLeft"))
{
scorePoint1 += 1;
Debug.Log("ScorePoint");
}
}
void Update()
{
Score1 = GetComponent<Text>();
Score1.text = "" + scorePoint1.ToString();
}
}
I have tried multiple answers and it seems like everything is connected UI wise (I have tested it with different stuff and it worked) its just this is not working. Im almost it is the scorePoint1 variable that is causing it as i have done it with other variables and it worked but as soon as i switched it out for that it no longer worked. Thanks for the help!
Quick edit: i did a null check as told to on the lines and i confirmed Score1.text = "" + scorePoint1.ToString() ?? string.Empty; this line is what is causing it. Still unsure how to fix it but atleast i know this for certain