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 KingCrizzo · Dec 10, 2012 at 12:08 AM · javascriptarrayvector3vector

How do I make an array of vectors?

This is for javascript. Pretty simple question. I want an array to store a series of vectors, but I don't know the syntax for creating and adding new vectors to the array. Thanks.

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
3
Best Answer

Answer by landon912 · Dec 10, 2012 at 12:31 AM

There are two types of arrays(there are more but lets focus on these two), the first is a native .NET array. The main differences are that it is static, meaning that the length has to be preset. In order to change the length it has to be remade. Another difference is that the built-in .NET arrays can be edited and set in the inspector. While remaking can be a pain for the CPU, if you arent going to remake them often or at all then they are the one to pick since they are faster.

 var values : float[];
 
 function Start () {
 // Since we can't resize builtin arrays
 // we have to recreate the array to resize it
 values = new float[10];

 // assign the second element(they start at 0)
 values[1] = 5.0;
 }

The second is a class. These are dynamic, meaning that they can be re sized at any time without remaking them. If you are going to resized them a TON this is the way to go since while they are much slower, you don't have to remake them(slower).

 var vectors = new Array();
     
 function Start(){
     vectors.Push(Vector3(0,0,0)); /// Add a entry, it will resize it to one and assign it.
     /// Manual or backend way(What is happening in the above line)
     vectors.length(2); ///Size up by one
     vectors[1] = Vector3(0,1,0); /// Assign second slot
 }
Comment
Add comment · Show 8 · 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 KingCrizzo · Dec 10, 2012 at 12:39 AM 0
Share

Exactly what I was looking for, thanks!

avatar image landon912 · Dec 10, 2012 at 12:42 AM 0
Share

Glad it helped :)

avatar image Bunny83 · Dec 10, 2012 at 12:44 AM 0
Share

The Array class is actually not UnityScript exclusive ;) It's just the .NET ArrayList class.

Always keep in $$anonymous$$d that both languages are .NET / $$anonymous$$ono languages. In general both (or all 3) can do the same things. However there are some language specific features which is unique for each language.

UnityScript isn't a standardized language. It's actually built on top of the boo compiler. So in general C# usually has more features since it was developed along with .NET, however .NET can do more than C# can so single languages can implement features which are possible in the framework, but not in other languages.

edit
I forgot to mention that the Array class should be avoided in all languages since it's dynamically typed. Use a generic list ins$$anonymous$$d. All languages support it.

If you still have trouble to get it working in UnityScript, just search and find things like that

avatar image landon912 · Dec 10, 2012 at 12:52 AM 0
Share

Thanks for fixing my mistake, i also agree that using the Array class is bad but my post doesn't seem to evaluate this, editing it now.

avatar image Eric5h5 · Dec 11, 2012 at 01:45 AM 1
Share

Thanks. :) Put "$$anonymous$$SDN [insert term here]" into Google and you should get appropriate links, for example Queue.

Show more comments

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

12 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

Related Questions

Filling an array with child vectors 2 Answers

Avoiding instantiating two things in same location? 1 Answer

Comparing vector 3 locations 1 Answer

Javascript - find a value in an array 0 Answers

Accessing Vector3s of GameObjects in Arrays (JS) 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