Today I\'ve come across an interesting bit of C# code in a Unity project:
MyScript ms = new MyScript(); //MyScript derives from MonoBehaviour
ms = null;
if(!ms)
No. You can do that in Javascript, but C# doesn't work like that unless myobject
is actually a boolean.
Based on this comment:
myobject ... derives from MonoBehaviour.
and this excerpt from the MonoBehavior docs:
Operators bool Does the object exist? operator != Compares if two objects refer to a different object.
It looks like you can do this for your variable, becuase it is implicitly convertible to bool
. But it's not generally okay for C#.