Keep different values of the same variable

Hello everyone,

I’m a begginer with programming and Unity. My question is:

Is it possible to store different values of the same variable? For.e.

I’ve got values for “rotation.x” and “rotation.y” that are constantly changing. Can I store that values in a moment of time inside variables? So I can compare/operate with other values of the same variables in the future. How?

what I try to achieve is: when the difference between rotation1.x and rotation2.x is positive/negative, change the position of an object to one side or another.

I tried with coroutines, but maybe im doing something wrong.

Sorry if im not very clear.

Thank you very much.

There is no reason why you can’t, just make them member variables. Say you want to have three “presets” for the player position, just do this

Vector3 pos1 = whatever you want;
Vector3 pos2 = whatever you want;
Vector3 pos3 = whatever you want;

void SetToPos(Vector3 pos)
{
    transform.position = pos;
}

//to set pos to pos1
SetToPos(pos1);

Yes, this is absolutely doable and it’s very common to use in programming.
The thing that you need is Lists, and you can store multiple values of the same data type.

This is how you initialize the list

List<float> tempRotationsList = new List<float>();


Then you store data to a list by doing this

tempRotationsList.Add(rotation.x); or tempRotationList.Add(rotation.y);

And you do this for every data type, just the value and type have to match. So you cannot add integers to the list of strings, but you can always convert them.