Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public static class PlaneCreator
- {
- public static GameObject CreatePlane(float width, float height)
- {
- GameObject go = new GameObject("plane");
- MeshFilter mf = go.AddComponent<MeshFilter>();
- MeshRenderer mr = go.AddComponent<MeshRenderer>();
- Mesh mesh = new Mesh();
- mesh.vertices = new Vector3[]
- {
- new Vector3(0,0,0),
- new Vector3(width,0,0),
- new Vector3(width,height,0),
- new Vector3(0,height,0)
- };
- mesh.uv = new Vector2[]
- {
- new Vector2(0,0),
- new Vector2(0,1),
- new Vector2(1,1),
- new Vector2(1,0)
- };
- mesh.triangles = new int[] { 0, 1, 2, 0, 2, 3 };
- mf.mesh = mesh;
- mesh.RecalculateBounds();
- mesh.RecalculateNormals();
- return go;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement