Help I can not understand how to do it with joints

There are 3 objects, one of them always stands in place of the second (A) can only move along one axis, how to do that when the object (A) moves, then the object in its middle changed its position as shown in the photo !

Try this, put a rigidbody component on your middle object, then on the two others cube, put a configurable joint component. On this component there is a “connected body”, drag on your middle object. Set the X,Y,Z Motion to “Locked”.

If you want to use joints, you will need rigidbodys on the object. However, if you just want to fake it, you can simple calc a vector and rotation between the objects. If you put this script on the object in the middle and populate ObjectA and ObjectB with the left and right cubes, it will make the object in the middle face object b on it’s Z axis.

using UnityEngine;

public class PositionBetweenObjects : MonoBehaviour
{
    public Transform ObjectA, ObjectB;

    private void Update()
    {
        //Get the center point between the objects
        var pos = (ObjectA.position + ObjectB.position) / 2;

        //Get rotation between objects
        //This calc may have to be altered depend on your setup as it will set the Z direction of the object towards objectB
        var rot = Quaternion.LookRotation(ObjectB.position - ObjectA.position, transform.up);

        transform.position = pos;
        transform.rotation = rot;
    }
}