How do I change a variable in Script A from inside Script B

I have a scriptA as a component of gameObjectA, and scriptB as a component of gameObject B.

I have some variables declared and used in scriptA, and I’d like to be able to change them from scriptB.

What are the simplest methods that people would suggest?

P.S. I’m using Javascript, and thanks in advance.

Scripts in Unity are components (like Renderer, CharacterController, Collider etc.), thus you must get a script with GetComponent(ScriptName). If scriptA and scriptB are both attached to the same object, get a reference to scriptA with GetComponent:

// assuming that ScriptA is the name of scriptA:
var codeA: ScriptA = GetComponent(ScriptA);
codeA.variable1 += 1; // modify the variables
codeA.variable2 = false;

If scriptA is attached to a different object, you must have a reference to this object:

// otherObject is a reference to the other object:
var codeA: ScriptA = otherObject.GetComponent(ScriptA);
codeA.variable1 += 1; // modify the variables
codeA.variable2 = false;

Any reference to the game object or any of its components works (transform, collider, renderer, other script references etc.)