checking other object variable

Hi people,

I would like to ask if it is possible to check a variable residing in another object.

I have already searched through the unity script reference, but it doesn’t answer the question

I don’t want to call a function and i don’t want to add,subtract, or translate, addforce etc.

I would like to check if a bool on object A is true or false so that object B may react accordingly

object B will be spawned many times and at many different intervals while Object A is always there until it collides with object B and Object A’s bool is true.

The trick is that the player will be changing the bool at will.

So to summarise the question.

How do i get Object B to check if Object A’s bool is true or false on contact?

Say your first script is just

public class code1 : MonoBehaviour {
    public bool foo = true;
}

then you’ll need another code which is like:

public class code2 : MonoBehaviour {
    public code1 _code;
    void Start () {
        if(_code.foo == true)
            doSomething();
    }
}

(This is written in C#)