Error CS0120 An object reference is required

Trying to create a way to delete instances when a key is pressed while the instance is touching another GameObject. I’m not sure if I’m accidently using code for the 3D physics engine or I’ve just done the code wrong.

public GameObject other;

void Update () {
    while (Collider2D.IsTouching(other))
    {
        if (Input.GetKeyDown("1"))
        {
            Destroy(other);
        }
    }
}

The code is completely wrong.

IsTouching works on an instance of an object i.e. it returns if a specific collider object is touching another collider object so you use it on an instance of a Collider2D and pass in another instance of a Collider2D.

In your code, you’re asking if the Collider2D CLASS is touching a specific GameObject which makes no sense (a Class doesn’t touch anything nor does a GameObject).

So get two references to both Collider2D objects you’re checking. I can’t give you example code because I have no idea what you’re doing. Certainly, the GameObject reference you have above needs to be Collider2D instead and set somewhere to the instance.