Hi,
I want to perform a simple check to see if some vertices of a mesh are in a simple cubic area, so I try to use Bounds.Contains() function but my script doesn’t show anything :
#pragma strict
//This script is attached to a simple cube primitive
var meshToTest : Transform;
private var mesh : Mesh;
private var vertices : Vector3[];
private var howManyVerts : int;
private var pastpos : Vector3;
function Start () {
//Get an array of all the vertices of a mesh
mesh = meshToTest.GetComponent(MeshFilter).mesh;
vertices = mesh.vertices;
print (vertices.Length + " verts in mesh");//a simple check to be sure in founds the vertices
print("coords: " + renderer.bounds.center);
pastpos = renderer.bounds.center;
}
function Update () {
if (renderer.bounds.center != pastpos){ //just to launch the detection if the cube is moved
print("bounding box has moved");
for (var i = 0; i < vertices.Length; i++){//looping through the array
if (i == 0){
print("vertex coords :" + vertices*);//just to ensure it goes in the loop (and it does at runtime)*
-
}*
_ if (renderer.bounds.Contains(vertices*)){//checking if the vertex position is inside cube’s bounding box*_
* howManyVerts++;*
* print (“found one!”);//this is never triggered at runtime :(*
* }*
* }*
* if (howManyVerts > 0){*
* print (howManyVerts + " vertices detected");//neither do this*
* howManyVerts=0;*
* }*
* pastpos = renderer.bounds.center;*
* }*
}
Unfortunately Unity doc regarding this function is quite short, and I don’t put the finger on what I’m doing wrong here. Please help.