- Home /
Manipulating arrays of Vector3s with pointers
I read somewhere that pointers are not possible with Unity, so maybe that's old information, or there's another way around this problem.
I'm trying to make an undulating mesh, kind of like the surface of water. I've got a X-by-Z grid of vertices that I've set up, triangulated, and added to a mesh. Currently I've given them random Y positions.
To easily go through their Y positions and change them in Update(), I really want to set up the vertices with pointers. Something like:
vertices[i] = new Vector3(xPos, *heightMap[i], zPos);
Is this not possible?
The only way I can think of doing it now is to go through the Object's Mesh component's vertices and recreating the vertex data every frame with new calls to Vector3.
Is there a better way?
Answer by MountDoomTeam · May 10, 2013 at 10:22 AM
that is very easy, and there is actually a code in the procedural examples that I modified to rewrite these kinds of things-you need to do transform point if the object should follow the equation wherever it is placed.
I didn't understand what you meant about using pointers, and you don't have to write all of the mesh vertices, but obviously if you want the mesh vertices to be different and you want to write the ones that you want to be different.
that is the standard way in programming I think, if you want to change vertices of actually have to write new vertices in the vertex array! There are some examples around.