hello , I am attempting to place the values of an array that are the same; inside of a separate.
this is a code i adopted and tried to use to move an objects verts , however; this script assigned points called “handles” to each vert as a child of the object . As a result , moving the handles results in simply pulling the mesh apart by individual verts.
I tried to group all the verts with the same Vector3 positions into an array and setting all the vector3 values of that array to be equal to the position of the handle.
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class VertHandler : MonoBehaviour
{
Mesh mesh;
Vector3[] verts;
Vector3 vertPos;
GameObject[] handles;
void OnEnable()
{
mesh = GetComponent<MeshFilter>().mesh;
verts = mesh.vertices;
foreach (Vector3 vert in verts)
{
vertPos = transform.TransformPoint(vert);
GameObject handle = new GameObject("handle");
handle.transform.position = vertPos;
handle.transform.parent = transform;
handle.tag = "handle";
//handle.AddComponent<Gizmo_Sphere>();
}
}
void OnDisable()
{
GameObject[] handles = GameObject.FindGameObjectsWithTag("handle");
foreach (GameObject handle in handles)
{
DestroyImmediate(handle);
}
}
void Update()
{
handles = GameObject.FindGameObjectsWithTag("handle");
for (int i = 0; i < verts.Length; i++)
{
verts _= handles*.transform.localPosition;*_
}
mesh.vertices = verts;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
}