- Home /
Question by
ISAKUPOLY · May 25, 2021 at 07:29 PM ·
runtimeanimationschild objectprefab-instance
Instantiate Prefab Child and Animate it through Parent in runtime?
I have a Parent GameObject where all the Scripting and Animator Controller is placed, Inside is a Child object (a Prefab of the basic player) like this:
PlayerParent (AnimatorController + Scripts)
GroundCheck
SomethingElse
AlsoSomethingElse
BasicPlayerPrefab
When I hit play, the animation works. But whenever I instantiate (in runtime) an other Prefab (the same Prefab but with other textures), the instanted prefab won't animate...
What do I have to do, so the Prefab animates just like the original prefab?
I instantiate a basic PlayerPrefab with this:
public void BasicSpawn()
{
Instantiate(BasicAsChild, transform.position, transform.rotation, ParentObject.transform);
}
And I "destroy" the old player with this function:
public void deleteOldPlayer()
{
Destroy(GetComponent<Transform>().GetChild(3).gameObject); //Everything at forth place will be deleted
}
First I use the "deleteOldPlayer()" function and then the "BasicSpawn()" function
The new player spawns but there is no animation going...
Comment