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 HyperX · May 12, 2012 at 08:09 PM · generationworldchunks

Generating Chunks

Hello, so i have finaly managed to generate chunks with a lot of help from this great community. So i want to generate only visible block for now, but i am stucked at there how to manage thath, i have now only chunks and 1 block generated, here is my code:

ChunkData.cs

 public class ChunkData
 {
     private int x, y, z;
 
     public ChunkData(int _x, int _y, int _z)
     {
         x = _x;
         y = _y;
         z = _z;
     }
 
     public int X
     {
         get { return x; }
         set { x = value; }
     }
 
     public int Y
     {
         get { return y; }
         set { y = value; }
     }
 
     public int Z
     {
         get { return z; }
     }
 
     public override string ToString()
     {
         return string.Format("Chunk ( {0},{1},{2} )", x, y, z);
     }
 }

WorldData.cs

 public class WorldData
 {
     private int chunkWidth = 32, chunkHeight = 128, chunkDepth = 32;
     private int chunksX = 8, chunksY = 1, chunksZ = 1;
 
     public ChunkData[, ,] chunks;
 
     public const int BottomChunkBorderRow = 0, LeftChunkBorderColumn = 0;
 
     public void InitChunkGrid()
     {
         chunks = new ChunkData[chunksX, chunksY, chunksZ];
 
         for (int x = LeftChunkBorderColumn; x <= RightChunkBorderColumn; x++)
         {
             for (int y = BottomChunkBorderRow; y <= TopChunkBorderRow; y++)
             {
                 for (int z = 0; z < chunksZ; z++)
                 {
                     chunks[x, y, z] = new ChunkData(x, y, z);
                 }
             }
         }
     }
 
     public int ChunkWidth
     {
         get { return chunkWidth; }
         set { chunkWidth = value; }
     }
 
     public int ChunkHeight
     {
         get { return chunkHeight; }
         set { chunkHeight = value; }
     }
 
     public int ChunkDepth
     {
         get { return chunkDepth; }
         set { chunkDepth = value; }
     }
 
     public int ChunksX
     {
         get { return chunksX; }
         set { chunksX = value; }
     }
 
     public int ChunksY
     {
         get { return chunksY; }
         set { chunksY = value; }
     }
 
     public int ChunksZ
     {
         get { return chunksZ; }
         set { chunksZ = value; }
     }
 
     public int TopChunkBorderRow
     {
         get { return chunksY - 1; }
     }
 
     public int RightChunkBorderColumn
     {
         get { return chunksX - 1; }
     }
 }

WorldGameObject.cs

 public class WorldGameObject : MonoBehaviour 
 {
     private WorldData world = new WorldData();
 
     public Transform chunkPrefab;
     public Transform[, ,] chunkGO;
 
     void Start()
     {
         world.InitChunkGrid();
 
         CreateChunks();
     }
 
     private void CreateChunks()
     {
         chunkGO = new Transform[world.ChunksX, world.ChunksY, world.ChunksZ];
 
         for (int x = 0; x < world.ChunksX; x++)
         {
             for (int y = 0; y < world.ChunksY; y++)
             {
                 for (int z = 0; z < world.ChunksZ; z++)
                 {
                     ChunkData curChunk = world.chunks[x, y, z];
 
                     Vector3 chunkInstPos = new Vector3(curChunk.X * world.ChunkWidth, 0, curChunk.Y * world.ChunkHeight);
 
                     Transform chunkInst = Instantiate(chunkPrefab, chunkInstPos, Quaternion.identity) as Transform;
 
                     chunkInst.parent = transform;
 
                     chunkInst.name = curChunk.ToString();
 
                     chunkGO[x, y, z] = chunkInst;
                 }
             }
         }
     }
 }

So i have created new empty game object called World Spawn and attached WorldGameObject to it, and attached Grass prefab (Cube with grass texture). Now it generates only 1 block in chunk. So my question is how i can generate more blocks in these chunks and if possible thath i generate only visible blocks.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KKABCD · Jul 09, 2013 at 01:09 AM

It doesn't matter about the code, but it depends on the prefab.

1) Go to your Prefab 2) Edit whatever you want in the scale section

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

how to create chunks in voxel terrain generation 1 Answer

About 2D open worlds (top down) chunking 1 Answer

Which is the best option (Procedurally world generation save) 1 Answer

Terrain Generation for Procedural World 1 Answer

2D Infinite Terrain Generation Performance Issues 0 Answers


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