Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool screenExists = false;
- Texture2D tex;
- string url = "www.e3.com/stream.png";
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.P) && !screenExists)
- {
- GameObject screen = new GameObject();
- screen.AddComponent<MeshFilter>();
- screen.AddComponent<MeshRenderer>();
- Mesh mesh = BuildQuad(0.32f, 0.18f);
- screen.GetComponent<MeshFilter>().mesh = mesh;
- tex = new Texture2D(640, 360, TextureFormat.DXT1, false);
- screenExists = true;
- }
- if (screenExists)
- {
- using (WWW www = new WWW(url))
- {
- yield return www;
- www.LoadImageIntoTexture(tex);
- GetComponent<Renderer>().material.mainTexture = tex;
- }
- }
- }
- private Mesh BuildQuad(float width, float height)
- {
- Mesh mesh = new Mesh();
- // Setup vertices
- Vector3[] newVertices = new Vector3[4];
- float halfHeight = height * 0.5f;
- float halfWidth = width * 0.5f;
- newVertices[0] = new Vector3(-halfWidth, -halfHeight, 0);
- newVertices[1] = new Vector3(-halfWidth, halfHeight, 0);
- newVertices[2] = new Vector3(halfWidth, -halfHeight, 0);
- newVertices[3] = new Vector3(halfWidth, halfHeight, 0);
- // Setup UVs
- Vector2[] newUVs = new Vector2[newVertices.Length];
- newUVs[0] = new Vector2(0, 0);
- newUVs[1] = new Vector2(0, 1);
- newUVs[2] = new Vector2(1, 0);
- newUVs[3] = new Vector2(1, 1);
- // Setup triangles
- int[] newTriangles = new int[] { 0, 1, 2, 3, 2, 1 };
- // Setup normals
- Vector3[] newNormals = new Vector3[newVertices.Length];
- for (int i = 0; i < newNormals.Length; i++)
- {
- newNormals[i] = Vector3.forward;
- }
- // Create quad
- mesh.vertices = newVertices;
- mesh.uv = newUVs;
- mesh.triangles = newTriangles;
- mesh.normals = newNormals;
- return mesh;
- }
Advertisement
Add Comment
Please, Sign In to add comment