I am trying to access the vertices of a tree created with the unity tree creator. The tree is placed in a wind zone and moves correctly according to the wind. However, I want to use the vertices of the mesh for attaching an object their position so that is follows the movement of the tree.
But the vertices never change value in the array list, even though they move visually. How can this be?
void Awake () {
tree = GameObject.FindGameObjectWithTag("Tree");
treeMesh = tree.GetComponent<MeshFilter>().mesh;
float closestDistance = 99999;
for(int i = 0; i < treeMesh.vertices.Length; i++){
float tempDistance = Vector3.Distance(transform.position, treeMesh.vertices*);*
-
if(tempDistance < closestDistance) {*
-
closestDistance = tempDistance;*
-
closestIndex = i;*
-
}*
-
}*
-
}*
void Update () {
-
transform.position = tree.transform.TransformPoint(treeMesh.vertices[closestIndex]);*
}