I’m quite new to Unity here and I have been trying to draw a couple of spheres on the vertex of a Cube gameobject. The code is as follows
public GameObject Elements;
public float gapWidth = 0.01f;
void Start()
{Elements = GameObject.CreatePrimitive(PrimitiveType.Cube);
Elements.name = "Ele1";
Elements.transform.position = new Vector3(0.0f * gapWidth + 0.5f, 0.0f * gapWidth + 0.5f, 0.0f * gapWidth + 0.5f);
Elements.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
Vector3[] vertices = Elements.GetComponent<MeshFilter>().mesh.vertices;
GameObject[] Spheres = new GameObject[vertics.Length];
for (int i = 0; i < vertices.Length; i++)
{
Spheres *= GameObject.CreatePrimitive(PrimitiveType.Sphere);*
Spheres_.transform.position = vertices*;_
_Spheres.transform.localScale -= new Vector3(0.8F, 0.8F, 0.8F);
}
}
- The problem here is that the spheres occur somewhere else in world space and not on the vertices of the Cube. I think I am going wrong somewhere in transform.position. Any help would be appreciated.*_