var vertices = new List();
GameObject mol = new GameObject();
mol.name = "Mol";
mol.transform.localScale = new Vector3(1, 1, 1);
mol.transform.position = new Vector3(0, 0, 0);
Mesh mesh = new Mesh();
mesh.vertices = vertices.ToArray();
mol.AddComponent<MeshFilter>();
mol.GetComponent<MeshFilter>().sharedMesh = mesh;
mol.AddComponent<SphereCollider>();
SphereCollider coll = mol .GetComponent<SphereCollider>();
coll.radius = 0.5f;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
for(int i = 0; i < vertices.Count(); i++)
{
GameObject ins = Instantiate(obj, vertices*, Quaternion.identity);*
ins.transform.SetParent(mol .transform);
}
I have a list of vertices of a molecule and I have to generate a sphere to each vertices (in order to generate the molecule). In 1 molecule , there are more than 7,000 vertices which means that I have to generate at least 7,000 sphere. So the unity is so slow and laggy.
=> What should I do to generate many spheres without making unity slow and laggy?
=> Another problem is I set the localScale and position of “mol” but it’s not working. The spheres are generated at the vertices position with its original scale.