- Home /
Instantiating prefab camera
Hi,
I'm able to instantiate my player prefab and move it around. How do i connect a camera to my player ? When i create the prefab with a camera, the camera itself does not work. A push in the right direction would be appreciated. Eddy.
Answer by appels · May 23, 2010 at 10:45 AM
Thanks for the push in right direction :)
I found what i needed and it works. This seems to work for me :
if (!target)
target = GameObject.Find("Player(Clone)").transform;
and i had to leave the target unasigned in the editor. Eddy.
Answer by qJake · May 23, 2010 at 08:21 AM
You can "connect" a camera to a player object in one of two (common) ways:
- Have a script that "follows" the player by tracking is Transform component.
- Attach the player to the camera (or the camera to the player) by parenting one to the other (drag one onto the other in the Heirarchy).
when i use a script in my main camera with the smooth follow script and it's target set to my player object, the camera doesn't follow. For the second option, i can't drag my object to it because it's not instantiated.
You must be doing something wrong with the smooth follow. You're probably setting the transform to the prefab, not the instance of the player. Instantiating a player object at runtime makes things more complicated.
Your answer
Follow this Question
Related Questions
Get transform of instantiated Prefab; Help appreciated. 1 Answer
Can't set camera target after instantiating a prefab(like respawn) 0 Answers
Instantiate prefab, strange problem 1 Answer
how to destroy camera instatiated from prefab? 0 Answers
Howto set main.camera as a parent when main.camera itself is a child of a prefab 1 Answer