Issue with storing gameobject data

I have a quick question regarding storing variables.

I have stored a gameobject’s local position and local scale in order to utilize it later. However, when I try to use it in code, it’s not recognized. I’m not sure if this is a syntax error or I’m incorrectly initializing the variables. Any suggestions are appreciated!

Thanks!

Quick Note: The error is saying that “size” and “Pos” are unrecognized symbols.

public class Duck : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
		Vector3 pos = transform.localPosition;
		Vector3 size = transform.localScale;
		
	}
	
	// Update is called once per frame
	void Update () {
	
		if (Input.GetKeyDown ("s")) {
			print ("S key pressed");

			transform.localScale = transform.localScale - new Vector3(0, 0.1F, 0);
			transform.position = transform.localPosition - new Vector3(0, 0.1F, 0);

			transform.localScale = Vector3 size;
			transform.localPosition = Vector3 pos;
		}

	}
}

When you put “Vector3 somevar;” your creating that variable within that “scope” of the code. Anything inside of Start () knows that variable, but not anything outside it. You should declare the variable outside of all methods, then just assign it in the Start method like “someVariable = something;” so you can access that variable outside the “scope” of Start ().

public class Duck : MonoBehaviour {

     Vector3 pos, size;
 
     // Use this for initialization
     void Start () {
     
         pos = transform.localPosition;
         size = transform.localScale;
         
     }
     
     // Update is called once per frame
     void Update () {
     
         if (Input.GetKeyDown ("s")) {
             print ("S key pressed");
 
             transform.localScale = transform.localScale - new Vector3(0, 0.1F, 0);
             transform.position = transform.localPosition - new Vector3(0, 0.1F, 0);
 
             transform.localScale = size;
             transform.localPosition = pos;
         }
 
     }
 }