How to share variables values between two if statements in the update function?

I’m using update as part of my character controller to perform different actions when a key is initially pressed, and when it is held down. The problem is, I would like to record a position.y (VARIABLE) a certain number of units above (3) my current transform.position.y (2). So how would I get the value of VARIABLE into the second statement? I know that the if () inherits values from update (), but i only want to record the value of VARIABLE when the key is initially pressed. Is there such a thing as backwards inheritance? Sorry, I’m quite new to C#.

void update ()

	if (Input.GetKeyDown (KEY))
	{
		VARIABLE = 2 + 3;
		dostuff;
	}

	if (Input.GetKey (KEY))
	{
		dostuff2;
		if (1 < VARIABLE)
		{
			dostuff3;
		}
	}

http://unity3d.com/learn/tutorials/modules/beginner/scripting/variables-and-functions?playlist=17117

Just declare them outside a function instead of inside one. That variable can be accessed anywhere in the script.

Do you mean something like this?

void update ()
{
         
    int VARIABLE = 0;

    if (Input.GetKeyDown (KEY))
    {
        VARIABLE = 2 + 3;
        dostuff;
    }
 
    if (Input.GetKey (KEY))
    {
        dostuff2;
         if (1 < VARIABLE)
         {
             dostuff3;
         }
     }

}

I did a quick google search to demonstrate the things you need to look for when declaring variables. Link here. I’m not really sure what you’re talking about with backwards inheritance or anything at all to be honest. If you’re new to C# then I suggest you brush up on the language and check out Unity’s tutorials.

EDIT: Sorry! I see that you are new to the language. Take some time to read through some beginner C# tutorials. I’d point you to some, but I’m trained in C++ and went backwards!