How can I detect if objects around has rigidbody on them?

I’m trying to upgrade a part of my script, disabling rigidbody gravity on all objects hit then raise their y axis while shift is held down. Everything works, except gravity.

Before I added the disableGravity, it worked perfectly. Holding down shift increased their y axis more and more until I let go (I have another part of my script increasing the variable TakeOffCharge).

Now with the disableGravity, all objects even without rigidbody flies up. How can I fix this?

		var explosionPos : Vector3 = transform.position;
		var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
		
		for (var hit : Collider in colliders) {
			if (hit.rigidbody && Charging == true && hit.transform.tag != "Player")
			hit.rigidbody.useGravity = false;
				hit.transform.position.y += TakeOffCharge * Time.deltaTime;
		}

Thanks in advance.

It seems that you forgot to put the last two statements in between brackets:

Try this:

       var explosionPos : Vector3 = transform.position;
       var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
 
       for (var hit : Collider in colliders) {
         if (hit.rigidbody && Charging == true && hit.transform.tag != "Player")
         {
            hit.rigidbody.useGravity = false;
            hit.transform.position.y += TakeOffCharge * Time.deltaTime;
         }
       }