- Home /
Why does this wont work? transfor.find()
the code exaple is self explanatory, why does this not works? i dont understand, this should work, but it just returns null, yes the player has its tag assigned, and the name of the childs path are correct, i dont understand, im doing something wrong?
private Transform target; // The position that that camera will be following.
private GameObject player;
player = GameObject.FindGameObjectWithTag("Player");
target = player.transform.Find("PlayerTurret/PlayerAimPoint").transform;
thanks in advance!!
AS @fafase said below line should work for you.I just tested it and it is working fine
target = player.transform.Find("PlayerAimPoint");
yes it does :) i was using the path wrong, thanksa lot! :)
"Does not work" is not a proper description of your problem. What doesn't work? Have you temporarily switched your inspector to debug mode to see the private variables? Which one(s) is/are null? Does it find the player? Any errors in the console?
If the player is found my guess would be the same as fafase suggests in his comment.
i was asking if doing GameObject.FindGameObjectWithTag("Player").transform.find("child/child").transform;
is a valid method, or if im triying something that is not possible.
Answer by fafase · Oct 31, 2015 at 12:26 PM
Is player hierarchy:
Player->PlayerTurret->PlayerAimPoint
or
PlayerTurret->PlayerAimPoint
if the second then you need:
target = player.transform.Find("PlayerAimPoint");
Also Find returns a transform so no need to get the transform.
Never$$anonymous$$d, i just found what was the problem, after about 2 hours of triying, your comment helped me, thanks a lot! it turns out the path i was using was incorrect :)
Your answer
Follow this Question
Related Questions
Finding Children question 3 Answers
Finding object with transform 1 Answer
Find Transform in the scene 2 Answers
Why is the rotation values I am accessing wrong? 2 Answers
This does not make sense this.gameObject.transform.Find() why? 2 Answers