- Home /
How to edit a mesh from a script
Hello everyone,
I want to edit a mesh from a script. But how do I edit the normals, vertices , scale it... and so on? The mesh is a sphere and I want to create a planet with it.
Answer by Jessy · Feb 13, 2012 at 04:21 PM
Google "unity mesh".
lol you think i didnt googled? I found the script reference. But its not working for me.
var mesh : $$anonymous$$esh = GetComponent($$anonymous$$eshFilter).mesh;
var vertices : Vector3[] = mesh.vertices;
var normals : Vector3[] = mesh.normals;
for (var i = 0; i < vertices.Length; i++)
vertices[i] += normals[i] * $$anonymous$$athf.Sin(Time.time);
mesh.vertices = vertices;
dont work on a plane or on a sphere. They just get invisible and thats all.
That code works for me, and they don't get invisible. As it sort of scale an objects alongs it's normals (so like a regular scale for a sphere, a translation for the plane) it's going to be bigger than the object-camera distance, and you don't see negative faces, that's why it's invisible. Look what's going on in your scene view.
Jessy : lmgtfy is awesome for that sort of thing ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613064039im_/https://answers.unity.com/themes/thub/images/avi.jpg)