Need Help C# - object parent

Hi! i got a problem when instantiate object and then parent it… the problem, that z axis is somehow changes to oposite of root coordinate…

public Transform[] ballsArray;
float random=Mathf.Round(Random.Range(-0.4f,(ballsArray.Length-0.6f))); 
Transform ball=Instantiate(ballsArray[(int)random], Vector3(Random.Range(-0.8f , 1.3f) , transform.position.y , 0.0f), transform.rotation)as Transform; 
ball.parent=transform; // after that ball coordinate changes,but i do not need that...

When an object becomes the child of another, its coordinates become relative to that other object. In other words, the new (0,0,0) of the child object becomes the position of the parent. This also counts for rotation and scale. This means that for the child object to retain its current position in the world, its actual transform coordinates must change. If not, it would move/rotate to some other position and possibly get scaled to another size as it inherits the parent’s transform.

Here is an example. Suppose you have two objects, A and B. Their positions are:

A.position = (1,0,0)
B.position = (-1,0,0)

That is, they are symmetrically on either side of the y-axis. Now, imagine we parent B to A, so now B becomes a child of A. To retain its position in the world, its position must become (-2,0,0), because now its new coordinate origin is A’s position. So its position in the world is (A.position + B.position) = (1,0,0) + (-2,0,0) = (-1,0,0), which is the same as its original position. Make sense?

This is why transform values of children change. Mathematically, this is known as a “change of base” in linear algebra - a conversion of points through matrix multiplication to transform them from one coordinate system to the next. (From A’s local coordinate system to the world’s, in the example). Exploring the mathematics of transforms in further detail is absolutely essential to anyone interested in the deeper mechanics of computer graphics.