Last active
January 6, 2023 09:31
-
-
Save cto-4piens/69a24560d21cff45691f1c3e899dde7f to your computer and use it in GitHub Desktop.
[unity] #unity #c-sharp
This file contains 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
public class MeshMaker : MonoBehaviour { | |
[SerializeField] private Texture texture = null; | |
void Start() { | |
Vector3[] vertices = new Vector[] { | |
new Vector3(-1f, 1f, -1f), new Vector(1f, 1f, -1f), new Vector3(1f, -1f, -1f), new Vector3(-1f, -1f, -1f) | |
}; | |
int[] triangles = new int[] { | |
0, 1, 2, | |
0, 2, 3 | |
}; | |
Mesh mesh = new Mesh(); | |
Vector2[] uvs = new Vector2[] { | |
new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(1f, 0f), new Vector2(0f, 0f), | |
}; | |
mesh.vertices = vertices; | |
mesh.triangles = triangles; | |
mesh.uv = uvs; | |
mesh.RecalculateBounds(); | |
mesh.REcalculateNormals(); | |
GetComponent<MeshFilter>().mesh = mesh; | |
Material material = new Material(Shader.Find(${shader_name})); //ex. "Standard" | |
material.SetTexture("_MainTex", texture); | |
GetCmponent<MeshRenderer>().material = material; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment