Problem with copying array that holds Raycasthit objects

Posted: Fri May 14, 2010 2:34 pm Post subject: Copying an array

it doesn’t seem to work…

here is how i tried to do it:

declaration

  var hitObjects : Collider[];
  var hits : RaycastHit[];

copying the array after some objects were hit:

Code:

     for (i=0;i<hits.length;i++) { 
          hitObjects _= hits*.collider;*_ 
 _*}*_ 
_*```*_
_*<p>later on i wanted to verify is everything is ok with this in OnGUI function but i get info only for hits[x] not for anything else: </p>*_
_*<p>Code:</p>*_
_*```*_
 _*for(var x=0;x<hits.length;x++){*_ 
 <em>_GUI.Label(Rect(10,10+((x+1)*15),400,30),hits[x].collider.name);_</em> 
 _*}*_ 
 _*for(var y=0;y<hitObjects.length;y++){*_ 
 <em>_GUI.Label(Rect(10,40+((y+1)*15),400,30),hitObjects[y].name);_</em> 
 _*}*_ 
_*```*_

Do a check, have you initialize the starting length for the hitObjects array?

After seeing comment: You have to use a Javascript Array, or an ArrayList, which supports dynamic size. You can take a look at this page

Or when using fixed size array

hitObjects = new hitObjects[hits.length];