Getting an error when i'm trying to use a nested foreach loop "unityengine.component does not contain a definition for GetEnumerator"

void Attack2()
{
var hits = Physics.OverlapSphere(AttackPoint.position, 0.5f);

        foreach (var hit in hits)
        {
            var hitables = hit.GetComponent(typeof(IHitable));

            if (hitables == null)
                   return;
           
            foreach(IHitable hitable in hitables)
                hitable.Hit();
            
            Debug.Log(hit.name);
        }
    }
  1. List item

With this code you should get exactly one IHitable, not an array which you are trying to loop through in the second for loop… hit.GetComponent(…) returns exactly ONE component of the given type, not an array…