- Home /
Few problems with arrays
for(int ib = 0; ib <= currentCollider.transform.gameObject.GetComponent<MeshFilter>().mesh.triangles.length / 3; ib ++){
Assets/Game_scripts/GridController.cs(49,150): error CS1061: Type int[]' does not contain a definition for
length' and no extension method length' of type
int[]' could be found (are you missing a using directive or an assembly reference?)
aPoints[] = GroundObject.GetComponent<MeshFilter>().mesh.vertices.Skip(i - 1 * 3).Take(3);
Assets/Game_scripts/GridController.cs(51,57): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
EDIT:
foreach (Vector3 tempPosition in tempPositionsList){
GroundObject.transform.position = tempPosition;
bool isFree = true;
// Check is object free space WIP
Collider[] hitColliders = Physics.OverlapSphere(GroundObject.transform.position, GroundObject.collider.bounds.extents.magnitude);
foreach(Collider currentCollider in hitColliders){
if(GroundObject.collider.bounds.Intersects(currentCollider.bounds)){
int adjustedTriangleCount = currentCollider.transform.GetComponent<MeshFilter>().mesh.triangles.Length / 3;
for(int i = 0; i <= adjustedTriangleCount; i ++){ // For every triangle in GroundObject...
for(int ib = 0; ib <= adjustedTriangleCount; ib ++){ // For every triangle in other object...
int[] aPoints = new int[3];
aPoints[] = GroundObject.GetComponent<MeshFilter>().mesh.vertices.Skip(i - 1 * 3).Take(3);
Vector3 a1 = GroundObject.transform.TransformPoint(GroundObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[1]]);
Vector3 a2 = GroundObject.transform.TransformPoint(GroundObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[2]]);
Vector3 a3 = GroundObject.transform.TransformPoint(GroundObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[3]]);
int[] bPoints = new int[3];
bPoints[] = GroundObject.GetComponent<MeshFilter>().mesh.vertices.Skip(i - 1 * 3).Take(3);
Vector3 b1 = currentCollider.transform.TransformPoint(currentCollider.transform.gameObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[1]]);
Vector3 b2 = currentCollider.transform.TransformPoint(currentCollider.transform.gameObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[2]]);
Vector3 b3 = currentCollider.transform.TransformPoint(currentCollider.transform.gameObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[3]]);
if(TriTriOverlap.TriTriIntersect(a1, a2, a3, b1, b2, b3)){
isFree = false;
}
}
}
}
}
if(isFree != false){
possiblePositionsList.Add (tempPosition);
}
}
I think that the writing is not good you have to use what like variable for aPoints ?
Answer by Anxo · Jan 02, 2015 at 05:39 PM
First, use Length not length, and I would optimize so you are not making the count every time by just making it once before the loop.
int adjustedTriangleCount = currentCollider.transform.GetComponent<MeshFilter<().mesh.triangles.Length / 3;
for (int ib = 0 ; i < adjustedTriangleCount ; i++){
}
WUCC
Skip in namespace Linq is interesting but not something I see with Unity's array class. $$anonymous$$aybe if you use List ins$$anonymous$$d you may have more luck, I am also not sure what you are trying to do with that line, if you explain your intentions, I would be happy to share an alternative path.
So I need to convert vertices to a list first. Doesn't that cost cpu? Is there any other solutions?
Its not too CPU heavy unless you have thousands of verts, all depends on how heavy your model is. But what is it you are trying to do with this line.
aPoints[] = GroundObject.GetComponent<$$anonymous$$eshFilter>().mesh.vertices.Skip(i - 1 * 3).Take(3);
$$anonymous$$aybe we can point you in another direction to accomplish the same thing.
Your answer
Follow this Question
Related Questions
A problem with intersection detection 1 Answer
Array index out of range error 1 Answer
A problem with arrays 1 Answer
Toggle Control between multiple turrets 0 Answers
Picking a Random Order for Levers 1 Answer