Last active
October 5, 2015 14:49
-
-
Save davepape/beadf4cf742b6b4784ed to your computer and use it in GitHub Desktop.
create a Unity mesh with UV texture coordinates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma strict | |
| // Script to create a mesh with 2 triangles with texture coordinates (UV). | |
| // This expects to be attached to a GameObject that already has a mesh | |
| // and material (such as a sphere), so that you can assign the texture | |
| // through the Unity editor, instead of here in the code | |
| // It uses the mesh's Clear() function to erase the old geometry before | |
| // creating the triangles. | |
| function Start () | |
| { | |
| var p0 : Vector3 = Vector3(-1,0,-1); | |
| var p1 : Vector3 = Vector3(0,1,-1); | |
| var p2 : Vector3 = Vector3(1,0,-1); | |
| var p3 : Vector3 = Vector3(0, -1,-1); | |
| var newVertices = [ p0, p1, p2, p3 ]; | |
| var newUV = [ Vector2(0,0.5), Vector2(0.5,1), Vector2(1,0.5), Vector2(0.5,0) ]; | |
| var newTriangles = [ 0, 1, 2, 2, 3, 0 ]; | |
| var m = GetComponent.<MeshFilter>().mesh; | |
| m.Clear(); | |
| m.vertices = newVertices; | |
| m.uv = newUV; | |
| m.triangles = newTriangles; | |
| m.RecalculateNormals(); | |
| } | |
| function Update() | |
| { | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment