Hi.
I need to use a multidimensional array to store information about certain GameObjects that i instantiate. Problem is that the dynamic JavaScript array turns everything into the type of Object. So when i call the function “Destroy()”, i am told that i give it the wrong argument (an object).
//Storing the data in my array
footstepRotation = (180/Mathf.PI)*(Mathf.Atan((currentPosition.z-lastPosition.z)/(currentPosition_.x-lastPosition*.x)));*_var spawnedFootstep : GameObject = Instantiate(footsteps,currentPosition_, Quaternion.Euler(0,footstepRotation*-90,0));*__*footstepArray.Add(spawnedFootstep);*__footstepArrayArray *= footstepArray;*_lastPosition _= currentPosition*;*__*//function to destroy the footsteps*__*Destroy(footstepArrayArray[0][0]);*__*
DO NOT use the JavaScript Dyanimc arrays. I have never gotten them to work the way they are supposed to.
just create a multi-dimensional array like this:
var footstepArrayArray : GameObject[,] = new GameObject[length1,length2];
for(var X : int = 0; X < footstepArrayArray.GetLength(0); X++)
for(var Y : int = 0; Y < footstepArrayArray.GetLength(1); Y++)
footstepArrayArray[X,Y] = Instantiate(something);
If you footsteps do not serve a Gameplay purpose in any way, shape, or form; then you only need a static Array to hold them. Just Destroy() the existing object in the array before putting a new one there. Then when your index >= array.length; index = 0; This way you will be able to keep all your footsteps in an easy to use collection, and it will delete them automatically.
If you need a dynamically sized Collection (the footsteps ARE important to your game), you might want to try a 1 of GameObjects, or a List of Lists of GameObjects
import System.Collections.Generic.List;
var footsteps : List.<GameObject> = new List.<GameObject>();
//you can add bits to the List by hand, or you can
// pass an array or another collection into the
// constructor to have the contents of your new
// list = contents of the parameter.
footsteps.Add(Instantiate(something));
//you can use a for-each loop to go through a List
for(var step : GameObject in footsteps)
{ doSomething(step); }
//another way to iterate through this collection
var stepArr : GameObject[] = footsteps.ToArray();
for(var count : int = 0; count < stepArr.length; count++)
doSomething( stepArr[count] );
var listOfLists : List.<List.<GameObject>> = new List.<List.<GameObject>>();
var list : List.<GameObject> = new List.<GameObject>();
listOfLists.Add(list);
for(var l : List.<GameObject> in listOfLists)
for(var stp : GameObject in l)
doSomething(stp);
I've tried this code in Unity and it wont compile: var listOfLists : List.> = new List.>(); It keeps showing expecting > but found >> Deleting the second > brings up a new error expecting > but found ; Can someone tell me what is the correct way to declare a list of lists?
As far as I know, the only way to typecast a value in Unityscript is to store the value in a variable of the correct type, like this:
var go: GameObject = footstepArrayArray[0][0];
Destroy(go);
It may solve the typecast problem, but I really don’t know how you will sweep the arrays of arrays to delete each element - hope you know what you’re doing!
I've tried this code in Unity and it wont compile: var listOfLists : List.> = new List.>(); It keeps showing expecting > but found >> Deleting the second > brings up a new error expecting > but found ; Can someone tell me what is the correct way to declare a list of lists?
– spinaljackOk found the answer, leave a space between then two end > >
– spinaljack