How to create collision between to specific objects? In c#.

Is there a way in c# to have a collision between to objects. for instance:
if(GameObject.Collision == to GameObject.collision)
or
if(Collision.GameObject == GameObject)

What I did was create an empty object and attached it to my main object(in this case a flying ship) and if that empty object collides with a part of my map, I will make my ship rotate upwards and go up in that direction off the y axis. My problem is I can’t get the collision to detect and of course make the ship rotate. Any help will be great. Thanks!

You must place your code in an OnCollisionEnter function - for instance:

void OnCollisionEnter(Collision col){
  if (col.gameObject.name == "Ground"){
    // object collided with something called "Ground":
    // do whatever you want: set a new direction, set a boolean variable, etc.
  }
}

But the empty object must have a kinematic rigidbody, or no collisions will be detected. An alternative is to make the collider a trigger (set Is Trigger in the Inspector) - in this case the event will be OnTriggerEnter:

void OnTriggerEnter(Collider other){
  if (other.name == "Ground"){
    // and object called Ground was touched by the trigger
  }
}

Notice that OnTrigger events pass the collider that entered the trigger, not a Collision structure. Again, you must add a kinematic rigidbody to the trigger to make it work.