- Home /
 
Array problem? help please!
my script doesnt make any error...but dont want to repond....i dont get it
 var InBag:GameObject[];
 var InBag2:GameObject[];
 
 function Refresh()
 {
 for(var x = 0; x < InBag.Length; x++){
 var obl:GameObject[]= GameObject.FindGameObjectsWithTag("Untagged");
 }
 for(var i = 0; i < obl.length; i++){InBag2+=[obl[i]];}
 }
 
               the var InBag2 is always empty on star...soppose i hav 5 gameObject in my InBag and i send message refesh from another script...dont worry its not the other script because i made it on start on this one to try....well my inbag2 saty empty....even if i have 100 stuffin my InBag...i just want to put the game object with certains tag to my other ''arrray''
I don't know anything about Unityscript, but in cs you have to cast it as an array type, like so:
 GameObject[] obl = GameObject.FindGameObjectsWithTag("Untagged") as GameObject[];
 
                  $$anonymous$$aybe something like that would fix your problem as well?
Answer by sparkzbarca · Mar 28, 2013 at 03:38 AM
arrays are not dynamic you have to declare a size of the array before you can fill it.
inbag2 = new gameobject[obl.length] perhaphs.
something like that
The thing is that you don't have to declare the size before you fill it. You can initialize an array with a method that returns an array (like using the gameobject.findgameobjectswihtag) or by assigning another array as its value.
Your answer