How do I check a variable of an instantiated object from another instantiated object?

In my case, I am making AI bots that mine rocks. As there will be multiple bots out mining at the same time, I need to add a script in the bots to check if there is already another bot mining that rock. At the moment I have been able to set a bool in the rock’s script to true, when a bot is mining it. I need help with a way to check this bool from the bot when it is choosing the next rock to mine.

so the easiest way is to raycast to the rock or fidn someway to get the rocks gameobject.

then just lets say we have a simple script called MineInfo

MineInfo.cs

int MineralCount;
public bool IsBeingMined;


then we have another attached to the miner

Miner.cs

//you'll need to get the rock somehow 
//if you need help doing that part ask
GameObject Rock;

Void CheckAllowedToMine()
{

if(Rock.getcomponent<MineInfo>().IsBeingMined)
{
//its already being mined
//do nothing, find another rock etc
}
else
{
//mine it
}
}