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 ZINKE · Nov 12, 2012 at 01:28 AM · javascriptarraysmultidimensional

Javascript Multidimensional Arrays

Hi, Im trying to animate a 3d array of game objects with GetSpectrumData(). But I can only get one line of cubes to move. I am still fairly new to programming (and I am sure this is not the most efficient way to code). But any help or advice would be appreciated.

var Audio : AudioListener; var numSamplesX : int; var numSamplesY : int; var numSamplesZ : int; var numberleft = new Array (); var multiplier = 1; var movementRadius : int; var thebarsleft = new Array(GameObject);

var abar : GameObject; var count = 0; var movementNerf : int;

function Start () {

 var spacingX = 1.05;
 var spacingY = 1.05;
 var spacingZ = 1.05;
 
 for(t = 0; t < (numSamplesZ/25); t++){
     for(i=0; i < (numSamplesX/25); i++){
     
         for (j=0; j < (numSamplesY/25); j++){
      
             var xpos = i*spacingX -8.0f;
             var ypos = j*spacingY -8.0f;
             var zpos = t*spacingZ -8.0f;

             var positionleft = Vector3(xpos,ypos, zpos);
             

             thebarsleft[i] = Instantiate(abar, positionleft, Quaternion.identity);
             thebarsleft[j] = Instantiate(abar, positionleft, Quaternion.identity);
             thebarsleft[t] = Instantiate(abar, positionleft, Quaternion.identity);  
     
         }
     }
 }

}

function Update () {

var numberleft = Audio.GetSpectrumData(numSamplesY, 0, FFTWindow.BlackmanHarris);

for(t=0; t < (numSamplesZ/25); t++){ for(i=0; i < (numSamplesX/25); i++){ for(j=0; j < (numSamplesY/25); j++){


if (count == 0) {

         thebarsleft[i].transform.localPosition.y += (numberleft[i]*(multiplier*(i+1)))/movementNerf;
         thebarsleft[j].transform.localPosition.y += (numberleft[j]*(multiplier*(j+1)))/movementNerf;
         thebarsleft[t].transform.localPosition.y += (numberleft[t]*(multiplier*(t+1)))/movementNerf;
         
         if (thebarsleft[j].transform.localPosition.y >= movementRadius){
         
         count = 1;
         
         }
         
     }
     
     if (count == 1) {
         
         thebarsleft[j].transform.localPosition.z += (numberleft[j]*(multiplier*(j+1)))/movementNerf;
         
         if(thebarsleft[j].transform.localPosition.z >= movementRadius){
               
         count = 2;
         }
         
     }
     
     
     if (count == 2){
     
         thebarsleft[j].transform.localPosition.x += (numberleft[j]*(multiplier*(j+1)))/movementNerf;
     
         if (thebarsleft[j].transform.localPosition.x >= movementRadius){
         
         count = 3;
         
         }
         
     }
     
     
     if (count == 3){
     
         thebarsleft[j].transform.localPosition.y -= (numberleft[j]*(multiplier*(j+1)))/movementNerf;
     
         if (thebarsleft[j].transform.localPosition.y <= -movementRadius){
         
         count = 4;
         
         }
         
     }
     
     if (count == 4){
     
         thebarsleft[j].transform.localPosition.z -= (numberleft[j]*(multiplier*(j+1)))/movementNerf;
     
         if (thebarsleft[j].transform.localPosition.z <= -movementRadius){
         
         count = 5;
         
         }
         
     }
     
     if (count == 5){
     
         thebarsleft[j].transform.localPosition.x -= (numberleft[j]*(multiplier*(j+1)))/movementNerf;
     
         if (thebarsleft[j].transform.localPosition.x <= -movementRadius){
         
         count = 0;
         movementRadius += 2;
         }
         }
       }
    }  
 }
 
 if (movementRadius > (movementRadius*2)) {
     movementRadius = 5;
 }

}

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 KiraSensei · Nov 12, 2012 at 10:20 AM 0
Share

What is exactly the problem ?

avatar image ZINKE · Nov 14, 2012 at 01:57 AM 0
Share

Basically, I am trying to make a nested array of 1000 cubes (10 x 10 x10 ) move to music independently. However, when I have any type of array set up I can only ever get the first layer to activate. Which means that only ten cubes are ever active at one time.

Is there a way to activate all 1000 of them at once in an array like grid?

(p.s. I apologize for my poor post educate. It was pretty late when I put it up)

avatar image cassius · Nov 14, 2012 at 02:09 AM 0
Share

Are you sure you're using multi-dimensional arrays? Usually when I use them I'll end up with something like: variable[counta][countb] where counta is the first dimension and countb is the second.

0 Replies

· Add your reply
  • Sort: 

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

11 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

Related Questions

Problem removing items from array 2 Answers

List problem? 2 Answers

Distance error: Cannot cast from source type to destination 0 Answers

Find colliders after collision? 2 Answers

Change rigidbody values on mutliple objects (ARRAY) 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