Hi folks, I’m very new to Unity (finally decided to drop XNA) and have been running into a few issues while porting my last project over.
I am creating an icosohedron programmatically and have only a camera and a directional light created in the editor (not programmitically). [These images show the settings][1].
I am drawing that pink icosohedrom programmatically with the following code:
// Create the mesh
GameObject newLedge = new GameObject("Geosphere"); //create a new gameobject. This gameobject will hold the mesh we’re creating.
Mesh newMesh = new Mesh(); //this is the mesh we’re creating.
newLedge.AddComponent<MeshFilter>();//this is what makes the mesh available to the other mesh components
newLedge.AddComponent<MeshRenderer>();//this is what makes the mesh visible
.........
// Assign
newMesh.vertices = vertices.ToArray();
int[] tris = new int[faces.Count * 3];
for (int i = 0; i < faces.Count; i++) {
tris[i * 3] = faces*.v1;*
_ tris[(i * 3) + 1] = faces*.v2;_
_ tris[(i * 3) + 2] = faces.v3;
}
newMesh.triangles = tris;
// Create the UVs*
* Vector2 uvs = new Vector2[newMesh.vertices.Length];
for (int i = 0; i < uvs.Length; i++)
{
uvs = new Vector2(newMesh.vertices.x, newMesh.vertices.z);
}
newMesh.uv = uvs;
// Tell lighting to see it*
* newMesh.Optimize();
newMesh.RecalculateNormals();
newLedge.GetComponent().mesh = newMesh;
newLedge.AddComponent();
It works great and shows the image. However, I cannot find a way to get it to be lit by the light and cast/receive shadows - these are the default settings:
[15178-unity4.png*|15178]*
Also, when I click in the editor when running, in the “MeshCollider” → “Mesh” button, it shows me this:
[15179-unity5.png|15179]
That is kind of how I’d like it to be shadowed.
I also looked into wireframing and put this code in the object that generates the icosohedron, but it never gets called… why is this not wired up to the object created?
void OnPreRender()
{
GL.wireframe = true;
}*_
* void OnPostRender()*
* {*
* GL.wireframe = false;*
* }*
Thanks for your help!
*[1]: http://imgur.com/a/Bjyr5*_
*
_*