Search Unity

Best way to make a level spawner?

Discussion in 'Scripting' started by dwhysall, Jun 20, 2018.

  1. dwhysall

    dwhysall

    Joined:
    Nov 22, 2012
    Posts:
    15
    Hi!

    I'm recreating one of my past games that was made in pure JavaScript.

    Pretty much, objects would come from the right side of the screen and you'd have to dodge them; the levels weren't random though and had set patterns.

    The way I created the levels was quite disgusting, I had relatively limited coding experience and simply made a levelTimer int, which would increment every frame, and then simply run a switch statement checking whether to spawn an object at that frame.

    Now remaking this in Unity, I'm sure there has to be a better way of doing this, and I'd love ideas because my brain is stuck!

    Sorry for the title - it's not clear but I couldn't think of a way to phrase it simply.

    Thanks!
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    If you're asking about the timer portion of spawning, I'd say a coroutine is good, or just keeping track of the time in a float in Update.

    If you need some more specific help or information, feel free to say so.

    Hope that helps. :)
     
  3. dwhysall

    dwhysall

    Joined:
    Nov 22, 2012
    Posts:
    15
    Do you think that's the best way to do it? I thought there would be a better architectural way to set it up.

    I suppose, on level load I could create a stack of the objects that will be used, and then pull them from it at the intervals that I want. It's just the 'timeline' bit that I'm sure there should be a better way.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Well, when I suggested tracking the time, I didn't mean the frame count like you mentioned in your post.
    I do not know what could be better. :)
     
  5. dwhysall

    dwhysall

    Joined:
    Nov 22, 2012
    Posts:
    15
    Ah, what do you mean by tracking the time?

    Edit: actually, no worries! I'm going to store the level data as JSON with all the details it needs and then parse it in.Thanks anyway!
     
    Last edited: Jun 20, 2018