i wanna to cheack if a variable is true from anther object but get component has to be the same object to control that so what should i do?
How about this …
// Put this in your Update() method, or wherever makes sense.
GameObject otherGameObject = GameObject.Find("/Scene/Path/To/OtherGameObject");
MyOtherComponent otherComponent = otherGameObject.GetComponent<MyOtherComponent>();
if (otherComponent.someVariable)
{
DoMyCoolStuff();
}
Remember to check for null values so you don’t get errors.
Alternatively you can add a public field to your component and edit it in the Inspector to point to the other component, like this:
// Put this with your other Inspector-tunable properties.
public MyOtherComponent otherComponent;
// Put this in your Update() method, or wherever makes sense.
if (otherComponent.someVariable)
{
DoMyCoolStuff();
}