- Home /
Problem with child position
Hi,I have a gun into my character and when i read the position of it i see some datas but when i want to see them from the code with "Debug.Log(transform.position)" i see the position of the parents.. why? Thanks in advance!
Your question is unclear. If you are talking about what is displayed in the Inspector that is the local position, and you would output it:
Debug.Log(transform.localPosition);
On the other hand 'transform.position' is the World position of the object. It is not the position of the parent unless the localPosition is (0,0,0). You output it:
Debug.Log(transform.position);
If for some reason you want the position of the parent, you can do:
if (transform.parent != null) {
Debug.Log(transform.parent.position);
}
Thanks a lot, i wanted to know how to have the localPosition of an object! Now it all works great!
Your answer
Follow this Question
Related Questions
Shoot second cell in 2d 0 Answers
transform.position on basis of rotation 0 Answers
Transform positions being strangely specific 1 Answer
can't use camera position in equasion, help! 2 Answers
transform position vectorially 2 Answers