Advertisement
Hyluss

Plane creator

Oct 17th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public static class PlaneCreator
  6. {
  7.     public static GameObject CreatePlane(float width, float height)
  8.     {
  9.         GameObject go = new GameObject("plane");
  10.         MeshFilter mf = go.AddComponent<MeshFilter>();
  11.         MeshRenderer mr = go.AddComponent<MeshRenderer>();
  12.         Mesh mesh = new Mesh();
  13.  
  14.         mesh.vertices = new Vector3[]
  15.         {
  16.             new Vector3(0,0,0),
  17.             new Vector3(width,0,0),
  18.             new Vector3(width,height,0),
  19.             new Vector3(0,height,0)
  20.         };
  21.  
  22.         mesh.uv = new Vector2[]
  23.         {
  24.             new Vector2(0,0),
  25.             new Vector2(0,1),
  26.             new Vector2(1,1),
  27.             new Vector2(1,0)
  28.         };
  29.  
  30.         mesh.triangles = new int[] { 0, 1, 2, 0, 2, 3 };
  31.         mf.mesh = mesh;
  32.         mesh.RecalculateBounds();
  33.         mesh.RecalculateNormals();
  34.  
  35.         return go;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement