Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by MBUnity · Nov 23, 2015 at 12:39 PM · 2dinstantiatearchitecturelevel-designinfinite runner

How to organize an Infinite runner level blocks

Hi there!

I'm working on an Infinite Runner game. I have created many level blocks(sections) with different obstacles and pick-ups for the player. They are positioned and placed manually, in such a way, to give the player a challenge. I thought that making every block a prefab and placing every obstacle and coin as a child of that prefab is going to be easier for me..because the player is going to run and these block prefabs are going to be randomly spawned in front of him and then destroyed after the player gets past them. It worked well.

Then I wanted to make a change on my coins. So naturally I took the coin prefab, made the changes, and applied them hoping that the change is going to take effect on all my blocks... Well..it didn't. Then I found out that nested prefabs don't work in Unity, so now I have to reorganize everything again?

How do I create organized level blocks, and then make them randomly spawn in front of the player? Is there any other option besides prefabs? Don't tell me I have to use a script for every block?

Think about Banana Kong, Temple Run, Subway Surfers. The levels seem random, but it's an organized randomness with certain portions of the level repeating themselves. That's what I'm trying to do, and I don't know how to organize it...

Thank you very much. I hope you guys can help me.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image lloladin · Nov 29, 2015 at 04:36 PM 0
Share

you shouldnt destroy and spawn the objects constantly since its pretty heavy on the cpu and can course laag ins$$anonymous$$d you could spawn all the objects in the start and have a loading screen and then reuse the objects also known as object pooling heres a link https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by OncaLupe · Nov 23, 2015 at 06:52 PM

Instead of putting the coins/pickups directly onto the prefabs, you can instead have empty game objects there as markers. When the section is spawned, you then spawn in the items at those locations.

This also gives you the ability to adjust how many coins or pickups are spawned on the fly. This way one section can have none/few/many coins/pickups without needing different prefabs for them. For instance, if you had just given the player a speed pickup, then spawn in a section with a marker for a pickup, you can decide if you want to give another so soon, give a different pickup, or skip it.

The best way (IMO) to do this is to have a simple script on each section that holds arrays with all markers in them (one for coins, one for pickups, etc). The spawner script can then use this to easily access the marker locations without needing to use GameObject.Find or whatever.

Also, it might be a good idea to look into object pooling since you're doing a lot of creation/destruction of objects. Instead of creating each section/coin/pickup and destroying them once past, you create a pool of each (guessing how many you may need max at any one time and adding a little buffer on top) and set them inactive. When needed you take one and position it then set it active.

http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MBUnity · Nov 23, 2015 at 09:16 PM 0
Share

Thank you so much for taking your time for this great reply!

That was a great insight. I will follow your advice :)

avatar image MBUnity · Nov 24, 2015 at 12:33 AM 0
Share

One more question. How should I organize these markers though? Let's say these markers are a prefab that has a script with public bools (checkboxes) for the type of object that the marker should spawn. I then put these markers into position, under my section object. I then save the section object as a prefab so I can use it whenever.

Now I want to make a change to my marker prefab (add another checkbox for example). That change won't affect any of the sections, because all the prefab connections are lost.

So how do I proceed? Should I create an empty game object with a single script that contains information about every single marker's position and everything? Is there any easier way?

Thank you.

avatar image MCoburn MBUnity · Nov 24, 2015 at 12:56 AM 0
Share

I'm unable to help you regarding the marker position thing, but I was going to say, for the checkboxes - why not use an enum? Just have something like this:

 public enum ItemsPossibleToSpawn { None, Health, Time, NitroBoost }
 public ItemsPossibleToSpawn whatItemToSpawn = ItemsPossibleToSpawn.None;

That way, when you want to spawn an item there, you just run:

 void SpawnAnItemHere() {
   switch(whatItemToSpawn) {
     case ItemPossibleToSpawn.Health:
       // Code to spawn the prefab here //
     break;
     // Repeat the above "case" statement until all items in the enum have been done excluding the "None" item. //
   }
 }

Enums are way easier to track than having 20 odd checkboxes and having if else loops that are massively complicated.

avatar image OncaLupe MBUnity · Nov 24, 2015 at 06:29 AM 0
Share

Scripts are a separate asset that the objects point to. If you change a script then all objects use the updated script. You'd only need to change the markers if you wanted to change what would spawn there. Probably wouldn't even need to make the markers a prefab, just create a new empty game object and drop the script on it.

Personally though, I wouldn't even put a script on the marker object, they'd just be an empty object. As mentioned in my answer, I'd have a script in the root of the section prefab with arrays for Coins and Pickups. Drag the markers to the proper array for what you want to spawn there. If you have multiple pickups, the code would decide what to spawn when the time comes.

If you did want to be able to pick what would show up ahead of time, then you can put simple scripts on the markers and the arrays would point directly to those scripts. Those scripts could then either have bools as you mentioned, or an enum like $$anonymous$$Coburn said. Enum would probably be simpler to code, but bools would give you the possibility to set multiple items to choose from if you wanted.

avatar image Le-Pampelmuse · Nov 24, 2015 at 08:26 AM 0
Share

This is turning into a discussion. Unity Answers is for answers. :)

If you want to discuss approaches on some features or functions, visit the forums here.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Projectile Instantiating at opposite position 0 Answers

Trying to spawn random falling rocks, can't figure out why it's not working. Help would be appreciated! 2 Answers

Can I import 2D .dwg floor plan to Unity? 1 Answer

Character Shooting Mechanic 2D Issues 0 Answers

Architectural help for 2D sprite-layered animations, re: customizable characters 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges