Is the idea of the MatchAllChildTransforms method in UnitRagdoll more to teach recursion? Personally I would use the built in Unity method GetComponentsInChildren and also SetPositionAndRotation (just found that one).
So I would end up with something like:
private void MatchAllChildTransforms(Transform original, Transform ragdoll)
{
Transform[] childTransforms = GetComponentsInChildren<Transform>();
foreach (Transform childTransform in childTransforms)
{
Transform cloneChild = ragdoll.Find(childTransform.name); //finds original transform
if (cloneChild == null) continue;
childTransform.SetPositionAndRotation(childTransform.position, childTransform.rotation);
}
}
Rather than:
private void MatchAllChildTransforms(Transform root, Transform clone)
{
foreach (Transform child in root)
{
Transform cloneChild = clone.Find(child.name);
if (cloneChild != null)
{
cloneChild.position = child.position;
cloneChild.rotation = child.rotation;
MatchAllChildTransforms(child, cloneChild);
}
}
}
Thanks for your time!