I am new to C# and I want to know if you have a public number variable and want to leave its value empty to allow your script to check if its input field is blank, does the following code work or is there a better/correct way to do it?
public class testscript : MonoBehaviour {
public int? num0;
void Start () {
if (num0==null) {
//blahblah~
}
}
}
Nullable (same as int?) doesn’t seem to be supported by the Unity inspector, so no, that wouldn’t work if you want to change the value directly in the inspector.
Thank you for the answers. I was dumb that I didn’t test it thoroughly because I was using a very old and slow computer. Upon trying it in another much faster computer, it turns out that Unity always default zero to any undefined number variable. So I would just define an exceptional number (e.g. -1) for the logical operator to check.