Search Unity

Generate one scene out of random connected levelsnippets

Discussion in 'Getting Started' started by TR33, Feb 6, 2017.

  1. TR33

    TR33

    Joined:
    Dec 27, 2016
    Posts:
    16
    Hey guys,

    I'm trying to find out how to generate one big level out of smaller scenes (imagine something like rolling sky). Because i am a lazy man and I dont want to have the same level al the time - Thats boring - i'm thinking about putting small parts of a level randomly together to a big one. But I have no idea how to do that. Can I generate prefabs of all levelsnippets I need and spawn them randomly after eachother? How can I override the spawnposition when the snippets are not equally long?
    I have read something about additive rendering but I didnt understand it really. Do I need to use something like this?
    BTW code is not needed. Nothing against your help but I want to try figure out the code by myself at least ;)
    I appreciate all of your help :)
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    There's really nothing to it. Yes, you can spawn prefabs wherever you want — pass in the desired spawn position to Instantiate, or simply assign to the .transform.position of the new object after you instantiate it.

    Or if you want to work by scenes rather than prefabs, you can call LoadScene with LoadSceneMode.Additive.
     
  3. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    I'd absolutely recommend prefabs over separate scenes. I think that's the direction most people are going these days.

    I'm not familiar with the game you're referencing, but I'm assuming it's an infinite runner of some sort. I'd have a LevelGeometryManager as an object in the scene. This component has a few GameObject arrays in it, one for straight pieces, one for turns, and one for obstacles including gaps that need jumped over or barrels to be dodged, etc.

    Your spawn point is not attached to these chunks of levels, but totally separate. Or part of your starting chunk, if you like. Then you spawn new chunks as the player moves, randomly choosing one from the appropriate array based on whether you want to go straight, turn, or have an obstacle.
     
    JoeStrout likes this.