get tube's bottom position

hi,
Considering my script: It works fine but when I rotate the tube by X axis, I will lose the tube’s bottom position. I wonder the reason for this. here is my code:

bottomPos = transform.position;
bottomPos.y = transform.position.y - transform.localScale.y / 2;

Sry for my poor English.

I assume from this code you are trying to find the bottom end of your tube, but if the object is rotated, the position is not correctly calculated by this code. There a a couple of different ways to solve this problem.

One easy way would be to attach a empty child object to the bottom, then you could get the position of the child object which would always be the position of the bottom of the tube in world space.

Another way would be to make the game object a child of an empty game object and then do your rotation on the empty game object. Then the localPosition of the bottom could be translated into world space to get the position.

A third way (untested) would be would be to multiply the transform.rotation by a relative vector for the bottom (0,transform.localScale.y/2, 0).