[solved] Keep the character the same apparent size by moving the plane

Hello everybody.
I am working on my editor and I am running into a problem.
I instantiate GameObjects in the scene through the ObjectField field. These objects can be Sprites or 3D objects.
In the case of sprites, I use the following code to keep them of the same apparent size while moving them away or closer to the camera or lowering or raising the plane on which they are placed:

mySprite.transform.localScale = Vector3.one * (Mathf.Abs((new Plane(cam.transform.forward,                                                              cam.transform.position).GetDistanceToPoint(                                                                                     mySprite.transform.position)) / Mathf.Abs(cam.transform.position.z)));

Using cam.ScreenPointToRay I also keep their position in Game View and everything works fine.

The problem I have with the 3D object which is a character. While moving it I don’t apply the resizing because I want it to resize normally according to its position relative to the camera.
However, when I move the plane on which it is positioned, the character apparently changes in size because it approaches or moves away from the camera.
Instead, I would like to keep its size even if I change its scale and then I move the plane.

Do you have any suggestions?

I found the answer.
The character is free to resize by moving it with the mouse on the Z axis but with the following lines it maintains its proportion both while I move the Plane or the Camera on the Y axis (Camera Z is fixed). Even changing its scale at any time.

Vector3 scale = ( (PlaneY - CameraY) * InitialScaleCharacter ) / InitialPlaneY - InitialCamY;
char.transform.localScale = scale;