PS1: a good trick is, ALSO just add a mesh collider with the same mesh, very simply so you can seee it in the editor, evene if you have not yet added an actual texture to the visual mesh. So simply add the line
PS2: you will eventually need some normals. Creating normals is an art form, it is not something that can be done by the same software every time. Unity gives you for free a “rough and ready” normals routine which can be handy during development. it is called RecalculateNormals(). Understand that later you will have to write your own subtle normals-making software. Here is a discussion about that issue Do we need to call RecalculateNormals() if normal vectors are assigned? - Questions & Answers - Unity Discussions
You are re-declaring the type of Vertices, UV, Triangle variables inside of the MeshSetup() method. As you have it now, they are treated as local variables, and their values are not assigned to the publicly declared variables of the same name, so, whatever is assigned to those values when the method runs are immediately forgoten when the method finishes.
This should work:
using UnityEngine;
using System.Collections;
public class Window2 : MonoBehaviour {
public Vector3[] Vertices;
public Vector2[] UV;
public int[] Triangles;
void MeshSetup(){
Vertices = new Vector3[] {new Vector3(-1,0,1),new Vector3(1,0,1),new Vector3(1,0,-1),new Vector3(-1,0,-1)};
UV = new Vector2[] {new Vector2(0,256),new Vector2(256,256),new Vector2(256,0),new Vector2(0,0)};
Triangles = new int[] {0,1,2,0,2,3};
}
void Start() {
MeshSetup();
Mesh stuff = new Mesh();
gameObject.AddComponent<MeshFilter>().mesh = stuff;
stuff.vertices = Vertices;
stuff.triangles = Triangles;
stuff.uv = UV;
}
}