Hyluss icon

Plane creator

Hyluss | PRO | 10/17/19 11:38:07 AM UTC | 0 ⭐ | 459 👁️ | Never ⏰ | []
C# |

960 B

|

None

|

0 👍

/

0 👎

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;
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎