Z axis change

Ok, so I am trying to find the best way to move an object from foreground to background. I know I can use axis input, but I was wondering if there was a way that say, when I hit a button it would set the z axis to a certain value, then hit a different button to move it back? Any input is great! (Btw I’m using c#)

This is not tested, but should work. Just add this script to your object, and also add a collider.

public test : MonoBehaviour
    {
       public float back = 1;
       public float front = -1;
    
       private bool isfront;
    
       void OnMouseDown()
       {
            if (!isfront)
            {
            transform.position = new Vector3(transform.position.x,
                  transform.position.y, front);
            isfront = true;
            }
            else
            {
             transform.position = new Vector3(transform.position.x,
                  transform.position.y, back);
            isfront = false;
            }
       }
    }

thanks, will try soon!