Actually, in this case, it’s from experience…
Way back in Unity’s earlier days, they thought it would be handy if all MonoBehaviours had access to the animator, the rigidbody, the collider, etc, so they included properties for them. Later, they decided that this was inefficient, and not the best way to manage the code, so they deprecated them.
In fact, I’ve been using Unity since 2014, and they’ve been deprecated since then.
Visual Studio Code should be noting that it is obsolete with a funny squiggle under the reference, and if you hover over it, you should see a message that it is deprecated. Digging into the latest source (using JetBrains Rider to access in my case), this is what you get in the MonoBehaviour class for the declaration of collider:
/// <summary>
/// <para>The Collider attached to this GameObject. (Null if there is none attached).</para>
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Property collider has been deprecated. Use GetComponent<Collider>() instead. (UnityUpgradable)", true)]
public Component collider
{
get => throw new NotSupportedException("collider property has been deprecated");
}
Now this is in the latest version which is 6000.0.12f1, where it’s not longer truly deprecated (deprecated normally means "ok, it will work, but just know we’re gonna change it), and instead will actually throw an exception.
Without direct access to the C# end of the source, looking for these signs in the compiler (or, supposing it actually compiled, running the program) should show you the message…
In Unity 6000, using transform.collider will not even compile, as that [Obsolete] tag prevents the compiler from linking it… If it DID somehow compile, then at runtime, you’ll get the red error message (and of course, the rest of the raytracing code will fail).
You can also always check the public API of any class… for example, here’s a link to the public API of the Transform class:
And one for the MonoBehaviour class:
If a property or method is not listed on these that you might have seen in older code, it’s likely deprecated.