Why do we use the "transform." in hit.transform.gameObject.tag?

Basically, I created this script, which obviously isn’t complete. destroyableObjectFInder is a Physics.overlapSphere. I got the if statement off of the internet, and out of curiosity, why do we use “transform.” and not just hit.gameObject.tag? Is it because transform is found in all objects, kind of like how child objects are accessed through the parents transform?

foreach(Collider hit in destroyableObjectFinder)
        {
            if (hit.transform.gameObject.tag == "Obstacles")
            {

            }
        }

Hi there,

You should be able to use “hit.gameObject”. It is unnecessary the use of transform there.

You can check the API on Collider and you will find out that gameObject is a property inherited, as it is transform.

Hope it helps.