i have this very simple if statement that acts very weird:
public Text ammoText; // Is assigned through the inspector
void SetAmmoText(){ // called on update
string ammoCount = "10"; // is constant for testing
if(ammoText == null)
Debug.Log("Ammo text is null");
else{
Debug.Log("Changing ammoText");
ammoText.text = ammoCount;
}
}
The Text object is assigned through the inspector and is there in runtime, the weird thing is that both Debug messages appear in the console without any errors.
If i write this:
void SetAmmoText(){ // called on update
string ammoCount = "10"; // is constant for testing
ammoText.text = ammoCount;
}
the code works (the text is changed) but i get a null reference exeption for the text object.
Thanks in advance.