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 tkdtom · May 23, 2013 at 12:07 AM · c#meshmultiplegeneration

How do I make multiple meshes in the same script?

Hi, I am trying to generate a series of planes between markers that the player can place in the game world, I've got code to generate the meshes but the last mesh is the only one that ever shows up, I've tried naming them and tried to set them as different game objects with no success, I was just wondering if anyone could help me out, this is my first C# project so I'm hoping I've just missed something simple:

 while (planeNo < markerNo)
             {
                 MeshFilter meshFilter = GetComponent<MeshFilter>();
                 if (meshFilter == null)
                 {
                 print("MeshFilter not found bro!");
                     return;
                 } 
                 markerStartX = (GameObject.Find("Marker "+planeNo).transform.position.x);
                 markerStartZ = (GameObject.Find ("Marker "+planeNo).transform.position.z);
                 planeNo ++;
                 markerEndX = (GameObject.Find ("Marker "+planeNo).transform.position.x);
                 markerEndZ = (GameObject.Find ("Marker "+planeNo).transform.position.z);
                 
                 
                 Vector3 p0 = new Vector3(markerStartX,0,markerStartZ);
                 Vector3 p1 = new Vector3(markerStartX,buildingHeight,markerStartZ);
                 Vector3 p2 = new Vector3(markerEndX,buildingHeight,markerEndZ);
                 Vector3 p3 = new Vector3(markerEndX,0,markerEndZ);
                 
 
                 Mesh mesh = meshFilter.sharedMesh;
                 //mesh.name = ("Mesh "+planeNo);
                 if (mesh == null)
                 {
                 meshFilter.mesh = new Mesh();
                 mesh = meshFilter.sharedMesh;
                 }
                 mesh.Clear ();
                 mesh.vertices = new Vector3[]{p0,p1,p2,p3};
                 mesh.triangles = new int[]
                 {
                 0,1,2,
                 0,2,3,
                 2,1,3,
                 0,3,1
                 };
                 
                 mesh.uv = new Vector2[4];
 
                 mesh.uv[0].x = 0; mesh.uv[0].y = 0;
 
                 mesh.uv[1].x = 1; mesh.uv[1].y = 0;
 
                 mesh.uv[2].x = 0; mesh.uv[2].y = 1;
 
                 mesh.uv[3].x = 1; mesh.uv[3].y = 1;
                 
                 mesh.RecalculateNormals();
                 mesh.RecalculateBounds();
                 mesh.Optimize(); 
                 meshNo ++;
                             
             }
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 robertbu · May 23, 2013 at 02:55 AM

What you are doing is taking a single game object and resetting the mesh for that single game object over and over. I'm not sure of your goal here. It is possible to make each of your planes a sub-mesh. Each sub-mesh can have its own material, but you don't gain much else, and it is difficult to code user interaction with sub-meshes.

Instead, if the user is to interact with these planes, I suggest each time through the loop: 1) Create a new game object, 2) Add a MeshFilter component to the game object, 3) Set the plane mesh for that MeshFilter. The results will be a game object per plane.

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

13 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

Related Questions

Multiple Cars not working 1 Answer

How can I generate a up facing quad mesh with variable resolution? 0 Answers

SetTriangles does not accept a NativeArray. Best way around this? 1 Answer

Strange Edge Shadows on Generated Flat Mesh 0 Answers

How can I generate a up facing quad mesh with adjustable res? 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