Can you get a bool from a tagged objects script?

I have a script in which i reference an object through its tag. I need this script to check a bool in that object, how could i do that, if its possible?

Using GetComponent<scriptwithboolean> u can request the script attached to your game object.

Another (cleaner) way is to use FindObjectOfType this looks for an object in your scene that has your boolean script, this way u cant make spelling mistakes and makes the code a bit faster.

GameObject go = GameObject.FindGameObjectWithTag("booleanobject");
scriptwithboolean script = go.GetComponent<scriptwithboolean >();
Debug.Log(script.myBool);

or

scriptwithboolean boolscript = FindObjectOfType<scriptwithboolean>();
Debug.Log(boolscript.myBool);