How to check if something is null?

Hey guys I have a script that creates joysticks, the problem is that when I load anoter level, this error appears:

MissingReferenceException: The object of type 'GUITexture' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

How can I make sure to make it null?

you can simply check it like this:

if (myTexture)
   GUI.DrawTexture(Rect(0,0,500,500),myTexture);

In C# you need to compare to null ...

if (myTexture != null)
   GUI.DrawTexture(Rect(0,0,500,500),myTexture);

If you want to check if the underlying object has been destroyed:

if (_yourTexture != null)

If you want to check for actual null reference:

Object.ReferenceEquals (_myTexture, null)

Keep in mind that your example threw a MissingReferenceException and not a NullPointerException. These might look like the same, but they mean different things. On NullPointerExceptions, the variable actually points to null. On MissingReferenceException, the underlying object might have been destroyed, but the script might still leave. This article explains the difference between them.