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 /
This question was closed Jan 20, 2016 at 10:39 AM by Hellium for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by EpyonDragon · Jan 20, 2016 at 09:32 AM · generatorbuildings

Trying to change from fixed to random.

hello, I'm still new to coding and I wanted to change my code here for a building generator from a fixed height/amount of floors to a random amount to give the buildings variety.I attached my code to see it.`enter code here` using UnityEngine; using System.Collections;

public class BuildingGenerator : MonoBehaviour {

 public GameObject[] Groundfloor;
 public GameObject[] Middle;
 public GameObject[] Roof;

 // Use this for initialization
 void Start () {
     int numberOfFloors = 5;

     for (int floor = 0; floor < numberOfFloors; floor++)
     {
         if(floor == 0)
         {
             AddLobby(0, 0, 0);
         }
         else if (floor < numberOfFloors - 1)
         {
             AddFloor(0, floor, 0);
         }
         else
         {
             AddRoof(0, floor, 0);
         }
     }
 
 }

 void AddLobby(float x,  float y, float z)
 {
     if(Groundfloor.Length > 0)
     {
         int index = Random.Range(0, Groundfloor.Length);
         GameObject newGround = Instantiate(Groundfloor[index]) as GameObject;
         newGround.transform.parent = transform;
         newGround.transform.localPosition = new Vector3(x, y, z);
     }
 }


 void AddFloor(float x, float y, float z)
 {
     if (Middle.Length > 0)
     {
         int index = Random.Range(0, Middle.Length);
         GameObject newFloor = Instantiate(Middle[index]) as GameObject;
         newFloor.transform.parent = transform;
         newFloor.transform.localPosition = new Vector3(x, y, z);
     }
 }


void AddRoof(float x, float y, float z) { if (Roof.Length > 0) { int index = Random.Range(0, Roof.Length); GameObject newRoof = Instantiate(Roof[index]) as GameObject; newRoof.transform.parent = transform; newRoof.transform.localPosition = new Vector3(x, y, z); } }

 // Update is called once per frame
 void Update () {
 
 }

}

Comment
Add comment · Show 2
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 Hellium · Jan 20, 2016 at 09:32 AM 1
Share
 int numberOfFloors = Random.Range(1,20) ;
avatar image EpyonDragon Hellium · Jan 20, 2016 at 10:06 AM 0
Share

thank you!

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Collision check 0 Answers

How can I model a building in Unity using lat, long, alt coordinates? 0 Answers

How can I use the text generator with the UI? 1 Answer

Make an enemy generator 0 Answers

How to make a electric/energy system? 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