Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by davidflynn2 · Jul 15, 2013 at 11:45 PM · c#y

World Spawn Changing Y to own Block

I am using the following script to create my world with a little help I have got it set up to spawn my blocks in all directions. The problem I currently have is that I need the Y to use its own blocks.

 using UnityEngine;
 using System.Collections;
 
 public class WorldSpawn : MonoBehaviour {
 
 
 public GameObject block1;
 public GameObject block2;
 
 int worldWidth  = 10;
 int worldHeight  = 10;
 int worldThickness = 4;
 float spawnSpeed = 0;
  
 void  Start ()
     {
 StartCoroutine(CreateWorld());
 }
  
 IEnumerator CreateWorld (){
  
     for(int x =0; x<worldWidth; x+=1) {
       yield return new WaitForSeconds(spawnSpeed);
      
     for(int z =0; z<worldHeight; z+=1) {
       yield return new WaitForSeconds(spawnSpeed);
     
      for(int y =0; y<worldThickness; y+=1) {//This is the one that I need to make use a differnt block.
       yield return new WaitForSeconds(spawnSpeed);//This is the one that I need to make use a differnt block.
                     
       GameObject block = Instantiate(block1,block1.transform.position, block1.transform.rotation)as GameObject;
  
       block.transform.localPosition = new Vector3(x, y, z);
  
       }
  
             }
       }
  
       }
 }
 
 
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 creighcl · Jul 16, 2013 at 12:09 AM 0
Share

when you say 'the Y' needs to use a different block, do you mean that you're using a different block when Y = 1 or some other number?

avatar image davidflynn2 · Jul 16, 2013 at 12:25 AM 0
Share

When it spawns the Y patter which is everything below the top layer I would like it to use a different block. Like the ground the top layer has grass on it aka my X and Z but under that you just have dirt aka my y. I need the y to use its own block so I can make it only dirt. Thanks.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by creighcl · Jul 16, 2013 at 01:00 AM

Forgive me if I still misunderstood, but it seems to me that since you're looping through x, y, and z - you'll just have to check what the Y value is and Instantiate the block based on that since you're building the world a column (up/down) at a time, then a row (on the z axis) across the x axis.

So you could do something like this, assuming that the top layer is block1 (or grass) and everything below the first block is block2 (or dirt)

 IEnumerator CreateWorld (){
  
     for(int x =0; x<worldWidth; x+=1) {
       yield return new WaitForSeconds(spawnSpeed);
  
     for(int z =0; z<worldHeight; z+=1) {
       yield return new WaitForSeconds(spawnSpeed);
  
     for(int y =0; y<worldThickness; y+=1) {
       yield return new WaitForSeconds(spawnSpeed);
  
          if (y==worldThickness-1){ //when Y = the highest layer, do block1
          GameObject block = Instantiate(block1,block1.transform.position, block1.transform.rotation)as GameObject;
          } else {
          GameObject block = Instantiate(block2,block2.transform.position, block2.transform.rotation)as GameObject;
          }
       block.transform.localPosition = new Vector3(x, y, z);
  
       }
  
          }
       }
  
       }
Comment
Add comment · 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

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

16 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Help converting C# to Unityscript 1 Answer

Selecting and deselecting not working 0 Answers

I need help knowing if Im doin this Right 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