J
J
Jiffa2015-11-05 19:58:14
Game development
Jiffa, 2015-11-05 19:58:14

How to attach a camera to an object created from a prefab?

The problem is this: the camera has a script, the script has a public Transform target variable, I dragged the 'Hero' object from the hierarchy through the Unity interface. Everything worked as it should.
Then the structure changed a little: at the start of the Hero object, a 'Spaceship' child object is created from the prefab, and I wrote target = heroManager.Instance.Spaceship in the camera script;
As a result, at the start, the camera flies far away, where there are not even any objects, although in the inspector it has target == Spaceship
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jiffa, 2015-11-06
@Jiffa

I figured it out myself, the reason was that with Instantiate it was necessary to save a link to the object and take it in the target for the camera. Like this:
and transfer to the HeroSpaceship camera

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question