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 dragonstar89 · Sep 10, 2013 at 01:03 AM · meshvoxelminecraftchunk

Voxel C# source problems.

So, I'm working on a small project to make a browser game that's like Minecraft. I'm working along side YouTube instruction videos and some of the project is turning out good, but I'm currently facing two problems.

First, The z positioning walls will not draw. Here's my code:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 [RequireComponent (typeof(MeshFilter))]
 [RequireComponent (typeof(MeshCollider))]
 public class Chunk : MonoBehaviour {
     public int width = 20;
     public byte [,,] map;
     
     protected Mesh mesh;
     
     protected List<Vector3> verts = new List<Vector3>();
     protected List<int> tris = new List<int>();
     protected List<Vector2> uv = new List<Vector2>();
     
     protected MeshCollider meshCollider;
     
     // Use this for initialization
     void Start () {
         meshCollider = GetComponent<MeshCollider>();
         map = new byte[width, width, width];
         for (int x = 0; x < width; x++)
         {
             for (int z = 0; z < width; z++)
             {
                 map[x, 0, z] = 1;
                 map[x, 1, z] = (byte)Mathf.RoundToInt(Random.value);
             }
         }
         
         mesh = new Mesh();
         GetComponent<MeshFilter>().mesh = mesh;
         
         Regenerate();
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     
     public void DrawBrick(int x, int y, int z, byte block)
     {
         Vector3 start = new Vector3(x,y,z);
         Vector3 offset1, offset2;
         
         if(IsTransparent(x, y - 1, z))
         {
             offset1 = Vector3.left;
             offset2 = Vector3.back;
             DrawFace(start + Vector3.right, offset1, offset2, block);
         }
         if(IsTransparent(x, y + 1, z))
         {
             offset1 = Vector3.right;
             offset2 = Vector3.back;
             DrawFace(start + Vector3.up, offset1, offset2, block);
         }
                 if(IsTransparent(x - 1, y , z))
         {
             offset1 = Vector3.up;
             offset2 = Vector3.back;
             DrawFace(start, offset1, offset2, block);
         }
         if(IsTransparent(x + 1, y, z))
         {
             offset1 = Vector3.down;
             offset2 = Vector3.back;
             DrawFace(start + Vector3.left + Vector3.up, offset1, offset2, block);
         }
         
                 if(IsTransparent(x, y, z - 1))
         {
             offset1 = Vector3.right;
             offset2 = Vector3.up;
             DrawFace(start + Vector3.forward, offset1, offset2, block);
         }
         
         if(IsTransparent(x, y, z + 1))
         {
             offset1 = Vector3.left;
             offset2 = Vector3.down;
             DrawFace(start + Vector3.up + Vector3.back, offset1, offset2, block);
         }
 
     }
     public void DrawFace(Vector3 start, Vector3 offset1, Vector3 offset2, byte block)
     {
         int index = verts.Count;
         
         verts.Add (start);
         verts.Add (start + offset1);
         verts.Add (start + offset2);
         verts.Add (start + offset1 +offset2);
         
         tris.Add (index + 0);
         tris.Add (index + 1);
         tris.Add (index + 2);
         tris.Add (index + 3);
         tris.Add (index + 2);
         tris.Add (index + 1);
     }
     
     
     public bool IsTransparent(int x, int y, int z)
     {
         if ((x < 0) || (y < 0) || (z < 0) || (x >= width) || (y >= width) || (z >=width)) return true;
         return map[x,y,z] == 0;
     }    
     
     public void Regenerate(){
         verts.Clear();
         tris.Clear();
         uv.Clear();
         mesh.triangles = tris.ToArray ();
         for (int x = 0; x < width; x++)
         {
             for (int y = 0; y <width; y++)
             {
                 for (int z = 0; z < width; z++)
             {
                 byte block = map[x,y,z];
                 if (block == 0) continue;
                     
                 DrawBrick(x, y, z, block);
             }
         }
     }
         
     mesh.vertices = verts.ToArray();
     mesh.triangles = tris.ToArray();
     mesh.RecalculateNormals();
     
     meshCollider.sharedMesh = null;
     meshCollider.sharedMesh = mesh;
 }
 }

It's a C# script named 'Chunk.' The blocks generate, I can walk on them, but some of the walls will not generate. What directions do I need to set within the z - 1 and z + 1 areas?

Second, I made a file named 'PlayerIO' and I have to add a Chunk file (a C# one) to make the rest of it work with the tutorial. I'm able to add everything, but it won't let me add my chunk file! Here's the image:

alt text

When I drag the Chunk C# file into the Chunk section, the 'No Access' sort of cursor popsup, and it won't let me add it.

Does anyone know a solution to these problems? Thank you!

help.png (6.7 kB)
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 Benproductions1 · Sep 10, 2013 at 02:28 AM

Hello,

When referencing a object in a script, such as your variable chunk of type Chunk in PlayerIO, you need to reference an instance of that object, not the script (assembly) containing that object's (class's) definition. One example would be a prefab containing only an object with the Chunk script attached.

Hope this helps,
Benproductions1

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

Why isn't my mesh updating properly? 2 Answers

What to do to make the chunk check other chunks? 1 Answer

How to assign texture to a specific mesh in a chunk for a minecraft game? 1 Answer

Perfomance Issue With Minecraft Clone. 0 Answers

Frame Rate drops when creating mesh in mobile Voxel World? 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