FlowORemi
FlowORemi

Reputation: 67

How can I fix the position of child object in unity?

I'm making a health bar in unity and I've got a problem with health bar's position. When the Object, which is health bar's Parent rotate, health bar also rotate. So I fixed rotation but the position from the parent object is changing. I think it's because it can't ignore parent's rotation.
Is there any way to fix the health bar's position above it's parent?

Upvotes: 5

Views: 4606

Answers (1)

Menyus777
Menyus777

Reputation: 7007

In this case, do you really need this gameobject to have a parent? If yes, store its initial position, and set it every frame or when the parent moves, set the child position to this stored value.

gameObject.transform.position

is always the world position to get a relative position to it's parent use

gameObject.transform.localPosition

Upvotes: 2

Related Questions