How do I reference a variable from another script?

How do I reference a variable from another script? I am new and have been working on this for over twenty hours and I am super frustrated. I have tried many things and could not get it to do what I needed. I would greatly appreciate any kind of help. I either need to see how to reference the variable from the first script or how to access the variable from the method in the first script.

public class Key : MonoBehaviour


public bool fireCode;

public void fcodeOff() 
 fireCode = false;   

Heres the second script public class FireTRAP : MonoBehaviour 
{ public Key script;

This is where I get confused and not sure what to do. I can use script.fcodeOff(); in update and it is using the method from the other script but I need to reference the fireCode variable or the fireCode variable in that method.

Any help would be appreciated. Thank You,


Lets imagine FireTRAP script wants to access firecode variable (which resides at Key script):

First, yu must know that there could be more than Key scripts in the scene, and eachone have different values for fireCodevariable. So first of all we need to specify which keyscript in the scene is the one i want to read.

For this, you can do it from the inspector (if the key scriupt is in the scene before rpessing play) or via code. If the key script did not exist in the scene before pressing play, you will need to do from script.

Ok, lets see the FireTrap script (i changed the variabel name to not copnfuse:

FireTRAP : MonoBehaviour 
public Key KeyScript; <- I say "there is a variable of class Key wich, in this cript,  i will call it "KeyScript".
As KEyScript is public, i can drag and drop my `Key`script **FROM THE SCENE** into inspector. To do that, i just need to drag THE GAMEOBJECT THAT CONTAINT THE KEY SCRIPT into the slot of the inspector of the gameobject that contains FireTRAP script (this script)
void Start()
Debug.Log(KeyScrpit.fireCode); //Now try to read it and write in console to check

IF you can achieve this, go look some youtube in your language. Its really a simple thing, but you need to understand it.