Hey there! I have gone through some unity tutorials and Im currently trying out to make a third person shooter game, connected to photon. I have the main network script inside a gameobject that spawns in my player at 0,0,0 position and everything works great, the only problem is that I need to activate the moving script/mouse look etc after the character have been spawned into the world and this works fine just that I need to turn on my mouse look Z script " for moving the torso" this would have worked if it was a component direct connected to my player but it needs to be connected to the torso bone so it is a children for the player. I want to activate the players child " Playercontroller->Armature.001->Bone->Bone.001
The script is laying on the " Bone.001" but I cant get it to work
this is one example that I have tried
a little recursivity and some cycles are more than enough to find anything inside anything
method(Transform objectTransform)
{
if(objectTransform.ChildCount > 0)
foreach(Transform trans in ObjectTransform)
{
method(trans)
}
if(objectTransform.GetComponent<MyComponentOrScript>() != null)
{
//do what you need with the component
}
}
thats the main, idea, do not forget to add a break in your recursivity or cycles, good luck and happy coding
Any particular reason not to use GetComponentInChildren() on the root object? I mean, I presume your object hierarchy itself is all active, only the script itself disabled. If the child itself is disabled, it will not be found, in which case you will have to use Poncho’s answer to find it (and if you do, please accept his answer). I do have to ask though, if the child itself is disabled, why?
If you use GetComponentsInChildren(true), you will get the component regardless of whether it’s active or not. Thanks to Haraback for reminding me of that version of the method, with that argument!