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 Geta-Ve · Mar 31, 2014 at 11:39 AM · arrayvariableaudiolistenergetspectrumdata

Storing many array values in a variable

Quick question. Is it possible to store multiple array values in a variable without having to specify each and every array value itself?

IE. from array[0] to array[30] = var X

I ask, because I am attempting to create a (simple) spectrum analyzer to manipulate my game objects via music.

From what I have researched I should use AudioListener.GetSpectrumData() -- for the first int within that function I used 1024, splitting the spectrum into 1024 parts (I presume). I know I could go as low as 64, but I feel like the spectrum split wouldn't really give me a nice visual manipulation. That and writing out 0 to 64 still seems like a pain in the ass. :P

Thank you kindly!

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 flamy · Mar 31, 2014 at 12:00 PM

Actually this is pretty simple while using List and Linq

do something like this,

     List<int> temp;
     temp = new List<int>();

     temp.AddRange(Enumerable.Repeat(1,64));
     temp.AddRange(Enumerable.Repeat(3,64));

this will fill the list with 128 items first 64 will be 1 and next 64 will be 3.... this is one of the easiest available solutions.

if there are issues using list and the number of entries will always be the same ( i.e., 64), then you can just save the value once to an array like this

 int[] temp; 
 temp = new int[2];
 
 temp[0] = 1;
 temp[1] = 3;

and while retriving if u need 100th value in the array (assuming that there are 128 entries jus like the list example.) you can do something like

 temp[(int)Mathf.Floor(100/64)];

similarly for any array index values.

if the array size is varying and not 64 always, then you would have to manually write an function that fills the values.

 public void FillMyArray(ref int[] arr,int startIndex, int count,int value)
 {
 
    for(int i=0;i<count;i++)
    {
       arr[i+startIndex] = value;
    }
 
 }


and while using the function,

     FillMyArray(ref temp,0,32,1);
     FillMyArray(ref temp,32,64,3);
Comment
Add comment · Show 1 · 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 Geta-Ve · Mar 31, 2014 at 01:32 PM 0
Share

Hey flamy! I really appreciate your clear and concise answer. I will definitely be trying this out tomorrow, and will report back on how well it works out for me.

Thank you so much!!

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

22 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

Related Questions

Adding and Removing to a Inbuild Array 2 Answers

Variable Type for an Instance of any Script 2 Answers

how to get a variable like Layermask but for tags 2 Answers

String Access problem 1 Answer

Possible to use an array value as the name of a variable? 2 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