Any problems with this script?

I attached script B to generators (When you press “E”, value of “CountGenerator” in Script A will increase)

//Script B

var message : boolean = false;
var GeneratorGUI : GameObject;
var Generator1 : GameObject;
var useGui : boolean = true;

function OnTriggerStay(other : Collider)
{
	if(Input.GetButton("e"))
	{
		GeneratorGUI.GetComponent(GeneratorCountNumbers).CountGenerator++;
		disableGui();
	}
}

function disableGui () 
{
	Generator1.GetComponent(ActiveGenerator).useGui = false;
}

function OnTriggerEnter (other : Collider){
	if (other.gameObject.tag == "Player") {
		message = true;
	}
}
     
function OnTriggerExit (other : Collider){
	if (other.gameObject.tag == "Player") {
		message = false;
	}
}

function OnGUI()
{
	if(message)
	{
		if(useGui)
		{
			GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 300, 30), "Press E to activate generator");
		}
	}
}

I attached Script A to empty gameobject called “GeneratorGUI”

//Script A

static var CountGenerator : int = 0;
var Onemore : GUIText;
var Activated : GUIText;
var Gate : GameObject;
var GateOpenSound : AudioSource;

function Start()
{
	if(CountGenerator == 1)
	{
		Onemore.enabled = true;
		yield WaitForSeconds(3);
		Onemore.enabled = false;
	}
	if(CountGenerator == 2)
	{
		Activated.enabled = true;
		yield WaitForSeconds(3);
		Activated.enabled = false;
		Gate.animation.Play("OpenGate");
		GateOpenSound.Play();
	}
}

I don’t get any errors but function Start at Script A is not working. I mean it didn’t want to access it. I thought

(THIS IS FROM SCRIPT B)

GeneratorGUI.GetComponent(GeneratorCountNumbers).CountGenerator++;

will access Start function too. Do I need to add something at above script?

Try this:

Make a function to add in CountGenerator in script A, remove all from start function, and in this function, verify the count. Something like this:

function addCount(int value){

CountGenerator += value;

if(CountGenerator == 1)
    {
       Onemore.enabled = true;
       yield WaitForSeconds(3);
       Onemore.enabled = false;
    }
    if(CountGenerator == 2)
    {
       Activated.enabled = true;
       yield WaitForSeconds(3);
       Activated.enabled = false;
       Gate.animation.Play("OpenGate");
       GateOpenSound.Play();
    }
}

And when you add the count, make this call in script B:

GeneratorGUI.GetComponent(GeneratorCountNumbers).addCount(1);

So, you are trying adding the count, but in GeneratorGUI only verify the count on Start of the object (the start function is only called on start of the scene). Using this function to add the count, you add a value to the variable and verify the count.