GameObject colliding with a sprite?

So I have a sprite called “princess” and when a cube hits the princess I want the princess to be destroyed, and the game to end.

I have a script attatched to the princess shown here.

   private void OnCollisionEnter(Collision collision)
{
   if(collision.gameObject.name == "Cube")
    {
        Destroy(this.gameObject);
    } 
}

The cube is autogenerated, and so when it gets generated its name is Cube as of now when it the cube touches the princess it just goes right through her… anyway to destroy the princess? Thanks.

make Sure that your princess and cube have Collider on it and there is a Rigidbody attached to Princess

Visual and physics model can be completely separate. Even if your “princess” has a sprite visual model, it can have a 3D collider (or 2D if you want).

For collisions you need some kind of collider component on everything that should be able to collide, and rigidbody component as well if they move (this will make them dynamic collider - you should only ever move dynamic colliders, moving static colliders makes the physics system recalculate “everything”).

So your “Cube” can have a BoxCollider and a Rigidbody (you can make it move using RigidBody.AddForce()), while the “princess” can have SphereCollider, BoxCollider, or if it is controlled by user input, then a CharacterController (which is a special kind of collider). In the last case you also need to set the “princess’s” rigidbody to kinematic. The easiest way to move a CharacterController is by CharacterController.Move().