Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Jun 23, 2013 at 12:55 AM by AlucardJay for the following reason:

Too subjective and argumentative : not enough information

avatar image
1
Question by Jackop222 · Jun 22, 2013 at 04:12 PM · levelsgeneratedrandomly

How to make randomly generated levels from a set of prefabs?

I am a complete noob at coding so i don't really know what i am doing!

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 $$anonymous$$ · Nov 10, 2015 at 06:00 PM 0
Share

I have this snippet for you ;) (This is for 2D but you can modify it to work with 3D)

I must tell you that this is not a very good script, it have some limitations: It can only put a prefab in front of a prefab by a value you specify (this value is used for every prefab)

This thing does for some reason not seem to lag the game out when it is spawning the prefabs. I spawned over a million prefabs (it took a while XD) and the spawning did not lag the game, it only lags when there is too many objects

 using UnityEngine;
 using System.Collections;
 
 public class levelGenerator : $$anonymous$$onoBehaviour {
 
     public Transform[] prefabs;
     public int currentX = 0;
     public int NumberOfPieces = 500;
     public int currentPieces = 0;
     int prefabLength = 0;
     int rndValue;
     Random rnd = new Random();
 
     // Use this for initialization
     void Start () {
         prefabLength = prefabs.Length;
         currentX = 5;
         
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (!(currentPieces == NumberOfPieces))
         {
             currentPieces += 1;
             rndValue = Random.Range(0, prefabLength);
 
             Instantiate(prefabs[rndValue], new Vector3(currentX, 0, 0), Quaternion.identity);
             currentX += 5;
 
 
         }
 
     }
 }

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

17 People are following this question.

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

Related Questions

Trading card game. Need help scripting the cards. 1 Answer

The right way to generate levels like Knife Hit or Paint hit game style. 1 Answer

Is there a way to make universe like spore ? 4 Answers

Randomly Generated Terrain 2 Answers

Levels Loading Randomly 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