I’ve created a Vector3 array with the length of four with this code (these are declared globally):
var contactpointSide : Vector3[] = new Vector3[4];
var contactnormalSide : Vector3[] = new Vector3[4];
and the array size in the inspector shows 4. Whenever I run the code, though, the size of the array changes to 0, and when I try to add vectors to the array, it gives me an IndexOutOfRangeException. Nowhere in the code do I modify or do anything related to the length of the vector, so I don’t know why the vector size keeps changing to zero. Can anyone spot my problem or have any ideas?
Here’s the code, with the offending lines marked (with unrelated stuff removed):
function OnCollisionStay (collision : Collision)
{
for (var contact : ContactPoint in collision.contacts)
{
...
if(dotprod >= -0.5 && rotationprod > 0.7) // left
{
// stuff here
//THIS LINE//contactpointSide[0] = contact.point;
//THIS TOO// contactnormalSide[0] = contact.normal;
}
}
}