Get float[] values from a certain number to another

Hello everyone;
excuse me if I’m not so clear in this, but what I’m trying to do is something like this:
var channels : float; // which by the way equals to 100 and each one has a value

var ch1 : float;
var ch2 : float;
var ch3 : float;
var ch3 : float;

function Update() {
    // instead of this:
    ch1 = channels[0] + channels[1] >>>> channels[20];
    ch2 = channels[21] + channels[22] >>>> channels[40];
    //What should I do

So my question is How to make it easier to do the addition from float[0] to float[20] for example
Hope I was clear and I need this quickly please

Well, i have no idea what’s the point of this, but when you want to add up x values and store the result in a seperate variable you can simply use a for loop:

var channels : float[]; 
var count = 20;    
var ch : float[]

function Start()
    // initialize the ch array with "enough" elements
    ch = new float[channels.Length/count + 1];

function Update()
    // initialize all values with 0
    for(var i = 0; i < ch.Length; i++)
        ch *= 0;*

for(var n = 0; n < channels.Length; n++)
ch[n / count] += channels[n % count];
So in the ch array you will find your accumulated values:
ch[0] contains the first 20 values (0-19)
ch[1] contains the next 20 values (20-39)
ch[2] contains the next 20 values (40-59)
ch[3] contains the next 20 values (60-79)
ch[4] contains the next 20 values (80-99)

Make a function that takes 2 values, the start and end indexes of the array. Inside that function write a “for” loop that goes from “start” to “end”, and add the value of the array on that index into a temp variable, then return the variable.

This is an untested code in C#, but it should be easy to do this in UnityScript, it’s pretty simple:

float AddChannels(int startIndex, int endIndex) {
    float temp = 0;
    for (int i = startIndex; i <= endIndex; i++) {
        temp += channels*;*

return temp;

void Update() {
ch1 = AddChannels(0,20);
ch2 = AddChannels(21,40);
Also, note that adding channels[0] through channels[20] adds 21 values, while adding channels[21] through channels[40] adds 20 values. Maybe that’s intentional, but didn’t you mean to add from 0 to 19, then 20 to 39 and so on? If the channels array is of length 100 the last valid index would be 99.