Accessing a String variable in another script

Hi, I am trying to work out how to access an integer variable from another script.

For example, say I have 2 scripts. Script A and B.

In script A I have;

var Number:int[ ];

I create 3 numbers in unitys inspector as 1, 5, 3 respectively.

How can I change the value of either number in script B?

it’s all in there…

I feel confused. Your subject says you want to access a String variable, your post says you want to change an integer, your code says Script A has an integer array with three values then you ask how you change “either number” in Script B.

Accessing or changing values on another script is generally straight forwards though, but first of all, what are these scripts running on?

You will need to know how the scripts will find each other. If they’re on the same GameObject it’s as simple as GetComponent(ScriptB), if they’ll exist at design time, you can define a variable in Script A for Script B then assign it in the inspector. If they’re generated at runtime, you can do a find in in the Start function. Or as an absolute last resort you can use static variables.

Sorry, I originally had two questions but edited it to only one. I am doing this in Javascript.

I have tried the

var timer:float;
 
function Update(){
var number: Script = GetComponent(Script);
  timer += Time.deltaTime;
 
  if(timer > 5){
    Script.number+=5;
    timer = 0;
  }
}

I should of said it was for the first of the 3 numbers but could be changed to apply to either of the three.