Need clarity on if (missile)

I’m not understanding how the if (missile) line results in a true value. In trying to understand this I wrote the following code:

Projectile missile = collider.gameObject.GetComponent();
Debug.Log ("The value of missile = " + missile );

The following was logged on the Console: The value of missile = laser(Clone) (Projectile)

So how does " laser(Clone) (Projectile)" result in a logic “true”?

I should also add, that I felt this particular lesson was poorly explained - it was all about “do this” and very little “why do this”… just wanting to give constructive feedback here.

1 Like



This is just short hand for writing;

if(missile ! = null) 

Therefore, as it isn’t equal to null the condition returns true.

Your debug line isn’t really writing out the value, its being converted to a string representation.

Hope this helps :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms