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 /
This question was closed Apr 28, 2015 at 07:41 PM by Bunny83 for the following reason:

"Debugging Question"

avatar image
-1
Question by Pollitoyeye · Apr 28, 2015 at 04:55 PM · meshproceduralterrain generation

Procedural Generation

Well, I have knowledge of have but I'm new on C# and Unity, I've been trying to follow a tutorial wich generates a procedural terrain creating an empty object and modifying its mesh, I know this is probably a frecuently asked question but I couldn't find the solution, thanks in advance. This is the object wich has the script: alt text

This is how it looks once the game starts:

alt text

And the Code:

     int Width;
     public Material floorMaterial;
     void Start(){
         Mesh mesh = new Mesh ();
         MeshRenderer renderer = GetComponent<MeshRenderer> ();
         Width = 10;
         int Samples = 5;
         float edge = Width / (Samples - 1);
         
         // Create the vertices and texture coords
         var vertices = new Vector3[Samples * Samples];  
         var uvs = new Vector2[Samples * Samples];
         
         // Fill in the data
         for (int i = 0, p = 0; i < Samples; i++) {  
             for (int j = 0; j < Samples; j++) {
                 // Current vertex
                 var center = new Vector3(i * edge, 0, j * edge);
                 // Height of this vertex (from heightmap)
                 float h = SampleHeight(center.x, center.z);
                 center.y = h;
                 vertices[p] = center;
                 // UV coords in [0,1] space
                 uvs[p++] = new Vector2(i/(Samples - 1f),
                                        j/(Samples - 1f));
             }
         }
         GetComponent<MeshFilter> ().mesh = mesh;
 
         mesh.vertices = vertices;
         mesh.uv = uvs;
         mesh.RecalculateNormals();
         mesh.RecalculateBounds();
         mesh.name = "Terrain";
         renderer.material = floorMaterial;
     }
     public float SampleHeight(float x, float y) {  
         return Mathf.PerlinNoise(x, y);
     }


Comment
Add comment · Show 3
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 Cherno · Apr 28, 2015 at 05:38 PM 1
Share

You don't actually ask a question, and you don't say what the problem is.

avatar image _dns_ · Apr 28, 2015 at 06:43 PM 1
Share

Hi, you defines a list of vertices and UVs, but no triangles!

avatar image Bunny83 · Apr 28, 2015 at 07:39 PM 1
Share

Actually this question should have been rejected by our $$anonymous$$oderator Guidelines since it's a typical "Debugging Question". Also it's nice that you mentioned that you "follow a tutorial" but you did not mentiond which one.

0 Replies

  • Sort: 

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

Create the visual spring in Unity? 3 Answers

Procedural Cylinder Generation 2 Answers

Procedural generated mesh problem 1 Answer

Procedural mesh creation issue 1 Answer

Generate mesh from raycast positions, independent of rotations 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