How to Access Variable from Another Function (C# Answers Please)

How do you access a variable from another function? It may sound simple (or stupid) but for whatever reason I can’t access it’s value. I have something like this:

void start() {
var variable = 1;
}
void update() {
var var2 = variable;
}

I’m using C# and it’s giving me an error message saying variable doesn’t exist when I’m trying to use it’s value. What syntax should I use so it will know to use variable variable?

You need to do something like this:

var variable = 1;

void Start() {
variable = 2;
}

void Update() {
variable++;
}

Define your variable globaly by writing it on top of the method header

int variable;
void Start() {
    variable = 1;
}
void Update() {
   int variable2 = variable;
}