How can I remember values and use them later?

When I call a function with lets say 3 parameters, x, y and z.

x = 1, y = 1, and z = 1.

How can I remember this but the next time I call the function and x changed to 2 I want to be able to compare the 2 to the 1 and know that it changed or is different? but then change it directly after to 2 again?

so I know the old position, change it to the new one and can then compare it to the next object?

Hi, I think you should store the value in a class variable, for example x = 1, y = 1, z = 1.

You should use class variables for this…

Basic Example Class:

using UnityEngine;
using System.Collections;

public class compare : MonoBehaviour {

	public int x;
	public int prev_x;

	// Use this for initialization
	void Start () {
	
		//initialise
		x = 1;
		prev_x  = x;


	}
	
	// Update is called once per frame
	void Update () {

		// for example get the x of the current position of your gameobject
		x = this.transform.position.x;

		if (prev_x > x)
		{
			//do something
		}
	
		// set prev x to current one for next update
		prev_x = x;


	}
}