I get compile errors when i start to PLAY.
I just put this script to Sphere and get errors, please help.
Errors:
[COLOR=black][FONT=Consolas]using UnityEngine;[/FONT][/COLOR][FONT=Consolas]using System.Collections;[/FONT]
[FONT=Consolas]using System.IO; // Used for writing PNG textures to disk[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas]public class CubemapProbe : MonoBehaviour {[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Cubemap resolution - should be power of 2: 64, 128, 256 etc.[/FONT]
[FONT=Consolas] public int resolution = 256;[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] #region Cubemap functions[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Return screencap as a Texture2D[/FONT]
[FONT=Consolas] // [URL]http://wiki.unity3d.com/index.php?title=RenderTexture_Free[/URL] [/FONT]
[FONT=Consolas] private Texture2D CaptureScreen() {[/FONT]
[FONT=Consolas] Texture2D result;[/FONT]
[FONT=Consolas] Rect captureZone = new Rect( 0f, 0f, Screen.width, Screen.height );[/FONT]
[FONT=Consolas] result = new Texture2D( Mathf.RoundToInt(captureZone.width), Mathf.RoundToInt(captureZone.height), TextureFormat.RGB24, false);[/FONT]
[FONT=Consolas] result.ReadPixels(captureZone, 0, 0, false);[/FONT]
[FONT=Consolas] result.Apply();[/FONT]
[FONT=Consolas] return result;[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Save a Texture2D as a PNG file[/FONT]
[FONT=Consolas] // [URL]http://answers.unity3d.com/questions/245600/saving-a-png-image-to-hdd-in-standalone-build.html[/URL][/FONT]
[FONT=Consolas] private void SaveTextureToFile(Texture2D texture, string fileName) {[/FONT]
[FONT=Consolas] byte[] bytes = texture.EncodeToPNG();[/FONT]
[FONT=Consolas] FileStream file = File.Open(Application.dataPath + "/" + fileName,FileMode.Create);[/FONT]
[FONT=Consolas] BinaryWriter binary = new BinaryWriter(file);[/FONT]
[FONT=Consolas] binary.Write(bytes);[/FONT]
[FONT=Consolas] file.Close();[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Resize a Texture2D[/FONT]
[FONT=Consolas] // [URL]http://docs-jp.unity3d.com/Documentation/ScriptReference/Texture2D.GetPixelBilinear.html[/URL][/FONT]
[FONT=Consolas] Texture2D Resize(Texture2D sourceTex, int Width, int Height) {[/FONT]
[FONT=Consolas] Texture2D destTex = new Texture2D(Width, Height, sourceTex.format, true);[/FONT]
[FONT=Consolas] Color[] destPix = new Color[Width * Height];[/FONT]
[FONT=Consolas] int y = 0;[/FONT]
[FONT=Consolas] while (y < Height) {[/FONT]
[FONT=Consolas] int x = 0;[/FONT]
[FONT=Consolas] while (x < Width) {[/FONT]
[FONT=Consolas] float xFrac = x * 1.0F / (Width );[/FONT]
[FONT=Consolas] float yFrac = y * 1.0F / (Height);[/FONT]
[FONT=Consolas] destPix[y * Width + x] = sourceTex.GetPixelBilinear(xFrac, yFrac);[/FONT]
[FONT=Consolas] x++;[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] y++;[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] destTex.SetPixels(destPix);[/FONT]
[FONT=Consolas] destTex.Apply();[/FONT]
[FONT=Consolas] return destTex;[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Flip/Mirror the pixels in a Texture2D about the x axis[/FONT]
[FONT=Consolas] Texture2D Flip(Texture2D sourceTex) {[/FONT]
[FONT=Consolas] // Create a new Texture2D the same dimensions and format as the input[/FONT]
[FONT=Consolas] Texture2D Output = new Texture2D(sourceTex.width, sourceTex.height, sourceTex.format, true);[/FONT]
[FONT=Consolas] // Loop through pixels[/FONT]
[FONT=Consolas] for (int y = 0; y < sourceTex.height; y++)[/FONT]
[FONT=Consolas] {[/FONT]
[FONT=Consolas] for (int x = 0; x < sourceTex.width; x++)[/FONT]
[FONT=Consolas] {[/FONT]
[FONT=Consolas] // Retrieve pixels in source from left-to-right, bottom-to-top[/FONT]
[FONT=Consolas] Color pix = sourceTex.GetPixel(sourceTex.width + x, (sourceTex.height-1) - y);[/FONT]
[FONT=Consolas] // Write to output from left-to-right, top-to-bottom[/FONT]
[FONT=Consolas] Output.SetPixel(x, y, pix);[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] return Output;[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] #endregion[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Use this for initialization[/FONT]
[FONT=Consolas] void Start () {[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // CreateCubeMap must be called in a co-routine, because we need it to wait for the end[/FONT]
[FONT=Consolas] // of each frame render before grabbing the screen[/FONT]
[FONT=Consolas] StartCoroutine(CreateCubeMap());[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // This is the coroutine that creates the cubemap images[/FONT]
[FONT=Consolas] IEnumerator CreateCubeMap()[/FONT]
[FONT=Consolas] {[/FONT]
[FONT=Consolas] // Initialise a new cubemap[/FONT]
[FONT=Consolas] Cubemap cm = new Cubemap(resolution, TextureFormat.RGB24, true);[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Disable any renderers attached to this object which may get in the way of our camera[/FONT]
[FONT=Consolas] if(renderer) {[/FONT]
[FONT=Consolas] renderer.enabled = false;[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Face render order: Top, Right, Front, Bottom, Left, Back[/FONT]
[FONT=Consolas] Quaternion[] rotations = { Quaternion.Euler(-90,0,0), Quaternion.Euler(0,90,0), Quaternion.Euler(0,0,0), Quaternion.Euler(90,0,0), Quaternion.Euler(0,-90,0), Quaternion.Euler(0,180,0)};[/FONT]
[FONT=Consolas] CubemapFace[] faces = { CubemapFace.PositiveY, CubemapFace.PositiveX, CubemapFace.PositiveZ, CubemapFace.NegativeY, CubemapFace.NegativeX, CubemapFace.NegativeZ };[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Create a single face matching the settings of the cubemap itself[/FONT]
[FONT=Consolas] Texture2D face = new Texture2D(resolution, resolution, TextureFormat.RGB24, true);[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Use this to prevent white borders around edge of texture[/FONT]
[FONT=Consolas] face.wrapMode = TextureWrapMode.Clamp;[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Create a camera that will be used to render the faces[/FONT]
[FONT=Consolas] GameObject go = new GameObject("CubemapCamera", typeof(Camera));[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Place the camera on this object[/FONT]
[FONT=Consolas] go.transform.position = transform.position;[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Initialise the rotation - this will be changed for each texture grab[/FONT]
[FONT=Consolas] go.transform.rotation = Quaternion.identity;[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // We need each face of the cube to cover exactly 90 degree FoV[/FONT]
[FONT=Consolas] go.camera.fieldOfView = 90;[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Ensure this camera renders above all others[/FONT]
[FONT=Consolas] go.camera.depth = float.MaxValue;[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Loop through and create each face[/FONT]
[FONT=Consolas] for(int i = 0; i < 6; i++) {[/FONT]
[FONT=Consolas] // Set the camera direction[/FONT]
[FONT=Consolas] go.transform.rotation = rotations[i];[/FONT]
[FONT=Consolas] // Important - wait the frame to be fully rendered before capturing[/FONT]
[FONT=Consolas] // See [URL]http://answers.unity3d.com/questions/326384/texture2dreadpixels-unknown-error-not-inside-drawi.html[/URL][/FONT]
[FONT=Consolas] yield return new WaitForEndOfFrame();[/FONT]
[FONT=Consolas] // Capture the pixels to the texture[/FONT]
[FONT=Consolas] face = CaptureScreen();[/FONT]
[FONT=Consolas] // Resize to the chosen resolution - cubemap faces must be square![/FONT]
[FONT=Consolas] face = Resize(face, resolution, resolution);[/FONT]
[FONT=Consolas] // Flip the image across the x axis[/FONT]
[FONT=Consolas] face = Flip(face);[/FONT]
[FONT=Consolas] // Retrieve the pixelarray of colours for the current face[/FONT]
[FONT=Consolas] Color[] faceColours = face.GetPixels();[/FONT]
[FONT=Consolas] // Set the current cubemap face[/FONT]
[FONT=Consolas] cm.SetPixels(faceColours, faces[i], 0);[/FONT]
[FONT=Consolas] // Save the texture[/FONT]
[FONT=Consolas] SaveTextureToFile(face, gameObject.name + "_" + faces[i].ToString() + ".png");[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Apply the SetPixel changes to the cubemap faces to make them take effect [/FONT]
[FONT=Consolas] cm.Apply();[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Assign the cubemap to the _Cube texture of this object's material[/FONT]
[FONT=Consolas] if(renderer.material.HasProperty("_Cube")) {[/FONT]
[FONT=Consolas] renderer.material.SetTexture("_Cube", cm);[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Cleanup[/FONT]
[FONT=Consolas] DestroyImmediate(face);[/FONT]
[FONT=Consolas] DestroyImmediate(go);[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Re-enable the renderer[/FONT]
[FONT=Consolas] if(renderer) {[/FONT]
[FONT=Consolas] renderer.enabled = true;[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Update is called once per frame[/FONT]
[FONT=Consolas] void Update () {[/FONT]
[FONT=Consolas] [/FONT]
[FONT=Consolas] // Recalculate the cubemap if "R" is pressed)[/FONT]
[FONT=Consolas] if(Input.GetKeyDown(KeyCode.R)){[/FONT]
[FONT=Consolas] StartCoroutine(CreateCubeMap());[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] } [/FONT]
[COLOR=black][FONT=Consolas]}[/FONT][/COLOR]