Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to have a 2D array which has a number of rows relating to the number of game objects and 3 columns. I want each row to have the name of the game object and its position and velocity. Is this possible or are there a clash of data types? I was thinking this:

int barrelCount = GameObject.FindGameObjectsWithTag("Barrel").Length;

        barrelData = new GameObject[barrelCount, 3];

        //does this need to be less than or equal to?
        for(int i = 0; i<barrelCount; i++)
        {
            for(int j = 0; j<barrelCount; j++)
            {
                for(int k = 0; k<barrelCount; k++)
                {
                    barrelData[i,j,k] = [GameObject.FindGameObjectWithTag("Barrel"), barrelPos, barrelVelo];
                }
            }


        }

I know the above wouldn't work code wise, you cant ask for position and velocity from finding a game object, but its along the lines of what I would like. Am I going the wrong way about this?

share|improve this question
1  
It's called a struct or a class. Look these up. Very basically, they allow you to group together data. A constructor would take the place of your [] thing. – Ben Oct 1 at 11:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.