- Home /
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.
Answer by sparkzbarca · Jan 02, 2014 at 03:48 AM
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
}
}
Your answer
Follow this Question
Related Questions
Instantiated object script properties 1 Answer
Call instantiated object from other script. 1 Answer
Same script not working on all objects 1 Answer
Check object for motion 1 Answer
Drag Script Not Working 1 Answer