Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

best way to init and create new gameobject

Discussion in 'Scripting' started by twintower31, Dec 10, 2007.

  1. twintower31

    twintower31

    Joined:
    Oct 31, 2007
    Posts:
    89
    Hello,

    I have to create dynamically some gameobjects, prefabs and cameras that depend of the content of a XML file at the beginning of my game.
    Where can I put the code that is in charge of the creation of the gameobjects ?
    Inside the Start() script of the main Camera of my Scene ?
    Does a function like Scene.Init() exist ?

    Thanks,
     
  2. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    You generally would create an empty 'game controller' GameObject in the scene and drop all your world-affecting scripts onto it. Their Awake and Start events will fire when the level starts and you'll be able to create your other objects in there.

    You could put this stuff on the camera, but that might be a bit confusing if you, for example, need multiple cameras and have to remember which one is carrying the scripts.