I'm a beginner with Unity, but I know how to code. I'm open to tutorials, of course.
Ideally, I would like to code spacial vertices and connect them into a simple polygon. The polygon would then be animated by changing the vertices over time.
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityI'm a beginner with Unity, but I know how to code. I'm open to tutorials, of course.
Ideally, I would like to code spacial vertices and connect them into a simple polygon. The polygon would then be animated by changing the vertices over time.
As a Unity programmer, you usually do not work with polygons directly.
The usual way to create and animate 3d objects in Unity is not to do that with code. You usually do that by creating them in a 3d modeling program like Maya or Blender. These programs also allow you to define animations for the model. When you import the model into Unity, you can also import its animations. You can then trigger these animations through the Unity Animation System. This approach is both more design-friendly (3d modeling programs offer you WYSIWYG editing instead of just typing numbers and hoping they look good) and more performance-friendly (the deformation logic can be processed on the GPU).
But if you really want to create and manipulate 3d geometry in code (there are some edge-cases where this is indeed useful, like procedural generation for example), check out the class Mesh. It represents the geometry used by a MeshFilter component.
You can either create an entirely new mesh:
Mesh mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
Or you can obtain the reference to an existing mesh
Mesh mesh = GetComponent<MeshFilter>().mesh;
You can then manipulate that mesh:
mesh.vertices = /* Vector3[] of polygon corners */;
mesh.uv = /* Vector2[] of the UV texture coordinates for the polygon corners */;
mesh.triangles = /* int[] of indexes in the vertices array. Every 3 entries define one polygon */
When you are finished manipulating the mesh, you might need to update a couple precomputed values. Depending on what you changed and what kind of material you use, not all three of these might be necessary:
mesh.RecalculateBounds(); /* important for culling calculation */
mesh.RecalculateNormals(); /* required by some shaders */
mesh.RecalculateTangents(); /* required by some shaders */