Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
-1
Question by alexander11 · Aug 23, 2016 at 12:26 AM · c#unity 53dvector3add

How do i instantiate a Vector3[] ??

hello i am having some trouble trying to instantiate 'Vector3[] newVerts' on 'Vector3[] origVerts' like whats in Pic1 what i am trying to do is spawning newVerts on each origVerts, but the results i am getting are in Pic2,

i don't want to use the Instantiate function because i don't want to apply a transform/gameobject to it, does anyone know how to do this? @damagefilter

(i'll put my code down below so you know what i have done)

-Pic1. ( what i would like to achieve ) alt text

-Pic2. ( The Results i get with my code below ) alt text

Here is the code so you know what i have done.

 using UnityEngine;
 using System.Collections;
 
 public class Extruder : MonoBehaviour {
 
     public float rotAngle;
     public int stretch = 5;
     private MeshFilter mf;
     private Vector3[] origVerts;
     private Vector3[] newVerts;
     void Start()
     {
         mf = GetComponent<MeshFilter>();
         origVerts = mf.mesh.vertices;
         newVerts = new Vector3[origVerts.Length];
         Generate();
     }
     void Generate()
     {
         for(int i = 0, x = 0; i < stretch; i++ ,x++)
         {
             newVerts[x] = new Vector3(0,0,i);
         }
         mf.mesh.vertices = newVerts;
     }
     void OnDrawGizmos()
     {
         Gizmos.color = Color.white;
         for (int i = 0; i < newVerts.Length; i++)
         {
             Gizmos.DrawSphere(newVerts[i], 0.1f);
         }
         Gizmos.color = Color.green;
         for (int i = 0; i < origVerts.Length; i++)
         {
             Gizmos.DrawSphere(origVerts[i], 0.2f);
         }
     }
 }
 

capture32.png (85.9 kB)
capture33.png (46.1 kB)
Comment
Add comment · Show 7
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 Eric5h5 · Aug 23, 2016 at 02:19 AM 1
Share

Downvoted for abusing the notification system. It's abuse like this that caused me to have to disable notifications for user tagging. Way to ruin things for other people.

avatar image alexander11 Eric5h5 · Aug 23, 2016 at 03:42 AM 0
Share

Abusing the notification system, i cant use user tagging, wtf, why?

avatar image Eric5h5 alexander11 · Aug 23, 2016 at 03:56 AM 1
Share

You have no reason to tag users in a question like that. It's rude and disruptive to get notifications for something you're not involved with, not that I should even have to explain this. Nobody here is your personal answering service. The way it works is, you post a question, and anyone who has the knowledge and inclination posts an answer. You can use tagging once someone has become involved in the question by posting comments/answers.

Show more comments

2 Replies

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

Answer by saschandroid · Aug 23, 2016 at 08:44 AM

I guess the problem is that you are generating each new vertex at a different stretch position (z=i). You have to use 4 (or orgVertex.Length) times the same stretch value

 void Generate()
     {
         for (int i = 0; i < stretch; i++)
         {
             for (int x = 0; x < orgVerts.Length; x++)
             {
                  newVerts[x] = new Vector3(origVerts[x].x,0,i);
             }                  
         }
         mf.mesh.vertices = newVerts;
     }



Comment
Add comment · Show 3 · 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
avatar image alexander11 · Aug 23, 2016 at 11:53 PM 0
Share

That also didn't work ): .

avatar image saschandroid alexander11 · Aug 24, 2016 at 06:00 AM 0
Share

Sorry, I didn't test it ... here's the update:

 void Start()
 {
     ...
     newVerts = new Vector3[origVerts.Length * stretch];
     ...
 }
 
 void Generate()
 {
     for (int i = 0; i < stretch; i++)
     {
         for (int x = 0; x < origVerts.Length; x++)
         {
             newVerts[x + i * origVerts.Length] = new Vector3(origVerts[x].x, origVerts[x].y, i);
         }
     }
 ...
 }

avatar image alexander11 saschandroid · Aug 24, 2016 at 06:11 AM 0
Share

Thanks :D.

avatar image
0

Answer by aditya · Aug 23, 2016 at 04:57 AM

Your Generate method should be like this

      void Generate()
      {
          for(int i = 0, x = 0; i < stretch; i++ ,x++)
          {
              newVerts[x] = new Vector3(origVerts[x].x,0,i);
          }
          mf.mesh.vertices = newVerts;
      }
Comment
Add comment · Show 3 · 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
avatar image alexander11 · Aug 23, 2016 at 05:21 AM 0
Share

Sadly your method does not work as you can see in the picture below and i also get ERROR "Array index is out of range". alt text

capture34.png (21.4 kB)
avatar image aditya alexander11 · Aug 23, 2016 at 07:19 AM 0
Share

Then simply change the Y element too ...

newVerts[x] = new Vector3(origVerts[x].x,origVerts[x].y,i);

If this helped please accept the answer

avatar image alexander11 aditya · Aug 23, 2016 at 08:13 AM 0
Share

I have already tried that, it doesn't work D: It gives a similar result.

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

232 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 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What is Matrix4x4? 2 Answers

How can I generate a up facing quad mesh with adjustable res? 0 Answers

How do i Extrude a 2D mesh(or Model) from one point to another? 1 Answer

How do i create lines in scene view?? 1 Answer

Is there a similar Command to lineRenderer.SetVertexCount for mesh?? 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