How to set one objects transform of Z to another's Z without affecting Y and X?

I just started coding in C# and I want to try to make a board game that is in a checkerboard pattern. I made a row on the bottom of the board to change the location of the object. I want to change my Objects Z transform to another’s Z’s Transform without touching the Y and X. Plz Help!

Here is my code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour {
public Transform MySelf;
public Transform ZY0;
public Transform Z1;
public Transform Z2;
public Transform Z3;
public float YMove;
public float ZMove;

void Start (){
}

void Update()
{
if (Input.GetKeyDown (“d”)) {
if (ZMove == 1)
{
MySelf.position = Z1.position;
}
if (ZMove == 2)
{
MySelf.position = Z2.position;
}
if (ZMove == 3)
{
MySelf.position = Z3.position;
}
}
}
}

Try this:

transform.position = new Vector3(transform.position.x, transform.position.y, ZPosition);

If I understood good your script MySelf is the Transform that you want to move to the z position of the Transform Z1 (or Z2, Z3).

So you could use:

MySelf.position = new Vector3(MySelf.position.x, MySelf.position.y, Z1.position.z);