Check if Object is itself. C#

is there anyone out there who knows how i can check if the colliding object is object?
what i accualy mean is, is there something to do the following:

public Transform SomeOBject;
void OnCollidionEnter (Collision other){
print(“other is SomeObject”);

is there anything that does this? cause what i just typed is not possible, and gives shitloads of errors.
many thanks to the people who awnser!

Collision is not the same as Transform; they are two different types so they can’t be compared with operator ==. You can however compare two of the same type are identical.

All MonoBehaviour have access to these objects, you just need access to them by their identifiers: transform, Unity - Scripting API: Component.collider, rigidbody, and gameObject.

From here, you can see that Collision has information stored about the object it berlongs to. Namelt, it has a rigidbody, a transform, a gameObject, and a collider references.

Take your pick of which one you want to use.

Just a shot in the dark, try:

if(other.transform == SomeObject)

instead of


public Transform SomeObject;
 void OnCollidionEnter (Collision other)
     if(other.transform == SomeObject)
         print("other is SomeObject"); 

Well, if it’s the same type of object and there are multiple of them, you should give each object the same tag.

Then in your OnCollisionEnter function will be something like this:

void OnCollisionEnter( Collision other ) {
   if(other.tag == 'tag goes here'){
       print(other is other);

It’s also possible to use in place of the tag