How to find the gameobject of hit collider (raycast)?

I want to create something simple, where when you click an object, they will destroy themselves.
I’m sending out a ray, and then checking if the object hit has a tag called “Nails”

private void Update()
    {
        if (SwitchCam._deskMode==true)
        {
            RemoveSator.satorCoverInstance.transform.position = SwitchCam.objectSpawn.transform.position;
            RemoveSator.satorCoverInstance.transform.rotation = Quaternion.Euler(0, 0, -90);
        }
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))
            {
                Debug.Log("Sent out ray");
                CapsuleCollider cc = hit.collider as CapsuleCollider;
                if (cc!=null && cc.gameObject.CompareTag("Nails"))
                {
                    Debug.Log("Clicked");
                    Destroy(cc.gameObject);
                }
            }
        }
    }

Up until line 16, everything works. Using if(cc!=null) as a condition itself works,and all objects clicked who have a capsule collider are destroyed. But adding the part that verifies if the object has the tag “Nails” does not.
The tag is assigned on my gameobjects in the inspector, and all of the objects have capsule colliders, so I’m not sure what’s causing the issue.
If the object could be destoryed with cc.gameObject, I don’t know why CompareTag doesn’t work when I refer to cc.gameObject.

Can you post a screenshot of the tagged object inspector?

I’d suggest debugging the value of the tag that is on cc to make sure you are getting back what you expect.

9174131--1277336--upload_2023-7-26_15-28-25.png
there are three of these, identical to eachother except for the names

    private void Update()
    {
        if (SwitchCam._deskMode==true)
        {
            RemoveSator.satorCoverInstance.transform.position = SwitchCam.objectSpawn.transform.position;
            RemoveSator.satorCoverInstance.transform.rotation = Quaternion.Euler(0, 0, -90);
        }
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))
            {
                Debug.Log("Sent out ray");
                if (hit.transform.CompareTag("Nails"))
                {
                    Debug.Log("Clicked");
                    Destroy(hit.transform.gameObject);
                }
            }
        }
    }

Thanks, it returned false. I have no idea what happened, but I temporarily disabled the capsule collider on an object touching the nails, and it all worked. Maybe because the other object was bigger it made it hard to click the nails? Confusing, but its working