- Home /
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[i] = hits[i].collider;
}
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:
Code:
for(var x=0;x<hits.length;x++){ GUI.Label(Rect(10,10+((x+1)*15),400,30),hits[x].collider.name); }
for(var y=0;y<hitObjects.length;y++){ GUI.Label(Rect(10,40+((y+1)*15),400,30),hitObjects[y].name); }
Answer by Extrakun · May 14, 2010 at 03:19 PM
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];
no, i thought that it will automatically adjust the size according to the size of the array i am copying, how to do that?
It is only automatic when you add content to an array through the Inspector. In code, a normal array is not automatic. Look at the link above in the answer above for array lists and other types of collections that can resize on the fly.
Your answer
Follow this Question
Related Questions
Copy From Array to List without reference [C#] 2 Answers
Array.Copy still creating a reference. 1 Answer
Array.Copy in UnityScript 1 Answer
Get Material of Normal? 0 Answers
How to copy part of an array 2 Answers