Hi, I have a soldier's gameobject, and when his health goes to 0 I destroy this gameobject and I replace it with a soldier's ragdoll, the problem is that I want that the instantiated ragdoll has the same position and rotation (also for every child like arms,legs ecc..) of the precedent gameobject, but my script doesn't work because the ragdoll is istantieted in the t-pose... How could i adjust it?
var ragdoll: Transform = Instantiate(replacement, transform.position, transform.rotation);
var currentJoints= GetComponentsInChildren(Transform);
var ragdollJoints=ragdoll.GetComponentsInChildren(Transform)
for(var childRagdoll : Transform in ragdollJoints)
{
for(var childGameObject : Transform in currentJoints)
{
if(childGameObject.name.CompareTo(childRagdoll.name) == 0)
{
childRagdoll.position = childGameObject.position;
childRagdoll.rotation = childGameObject.rotation;
}
}
}
Destroy(this.gameObject);
Thanks in advice and sorry for my bad english!
↧