Determine object type from transform

I have an object’s transform from a raycast, and I would like to know what type of object I hit. Is there any way to tell? I have tried an expression like:

Type t = hit.collider.transform as Type

then testing to see if t is null, but I get a compiler error in the upcast.

Edit: To explain further, I have several types of objects in the scene. When the mouse is clicked, I am determining which object was clicked using a raycast from the screen. Different objects behave differently when clicked, so I need to know what type of object was clicked to know what to do with it, and I will need a reference to the object (not just its transform) to be able to call the appropriate methods on it.

You could use a different tag for each type and use if(hit.gameObject.tag == “yourtag”){}

Your question has no meaningful answer.

A transform will always be attached to a GameObject. Always. The type of a transform will not change, no matter what you do to your GameObject

What you want to do is see what components are on the GameObject. You could do

hit.collider.gameObject.GetComponent<MyComponent>()

Then check that for null. I’m pretty sure you could also do the same thing using GetComponents.

The normal way to do this in Unity is tag checking.