I am trying to create a method that remembers the previous variable value.
I have the following:
enum Direction { UP, DOWN, LEFT, RIGHT, NONE };
Direction myDirection;
Direction previousDirection;
private void Update()
{
if (Input.GetKeyDown(KeyCode.W))
{
myDirection = Direction.UP;
}
if (Input.GetKeyDown(KeyCode.A))
{
myDirection = Direction.LEFT;
}
if (Input.GetKeyDown(KeyCode.S))
{
myDirection = Direction.DOWN;
}
if (Input.GetKeyDown(KeyCode.D))
{
myDirection = Direction.RIGHT;
}
Now I want every time myDirecition changes, the previous state to be remembered in previousDirection