Overlapsphere : Count objects based on variable ?

Hi guys !

So here’s what I am trying to do.
I have a cube having a certain amount of a resource (water for example). I want this cube to detect other cubes around it and check if they have a lower amount of water.
If it is the case, I’d like my first cube to divide the amount of water it has in excess compared to the others and give some to every cube around.

Any idea on how to do this ?

This sounds like a great place to use Physics.spherecast, heres a link to the docs\


I would use hitinfo to find the GameObject inside the sphere

Hope this helps!