
I get this error ^^.
Code:
[SerializeField]
private Text ammoText;
private void Start()
{
ammoText = GetComponent<Text>();
ammoText.text = currentAmmo + "/" + reserveAmmo;
}
Why i get this error? I put in the UI Text element in the inspector.
So…ammoText is probably not set to anything.
Do you have a Text component on the same gameobject that this script is on?
Though…that error points to PlayerMovement…are you sure this is where your error is?
No i don’t have the script on the Text element itself. Thats why i use “[SerializeField] private Text ammoText”
GetComponent() says to look at the same gameobject and find a Text component. If none is found it returns null. So ammoText is null.
Ah yeah! Thanks man, very dumb fault from me.