Set a prefabs GameObject
Hey everyone!
Might have a tricky one here! For my player, I've made 2 Objects, the first one is for the camera and the other is for the body (so that the body doesn't rotate on it's x axes and only on it's y). Neither of them is the parent of the other. The camera follows the body.
Time for the problem. At the start of the scene want to instantiate them but, the camera doesn't pick up the body so it can follow it. I have to set it in game and it doesn't set it self automatically. I'm using the public Transform body; and telling it to have the same position as it. Any Idea of how I can fix this?
Thanks everyone for your help!
Ins$$anonymous$$d of Instantiating them both seperatly, what if you made 1 a child of the other, then after they've been instantiated, make them both seperate using transform.parent = null; ? That way the camera knows who the body is aswell as it not being a parent/child of it. Would this work?
Yeah that's what I ended up doing in the end. Thought I was an idiot for not having thought of it sooner!
Answer by Torigas · Mar 17, 2016 at 02:34 PM
You could create the following hierarchy and just instantiate the InstantiatedObject (empty GO with your two objects as children):
Instantiatedobject
player
camera
Yeah I did that in the end and then separated them after it because otherwise the body moves with the head on the x or y axis (can't remember)
Your answer
Follow this Question
Related Questions
How can i create only one Player gameobject in Network game? 0 Answers
Enemy Spawns Projectile towards player 0 Answers
Instantiate particle system attached to object 1 Answer
How to instantiate bullets in multiple transforms 1 Answer
Destroy instatiate object on trigger enter / collision,destroy instantiate prefab on trigger enter 0 Answers