Need help to understand a line of JS script (i'm a C# user :S)

Hi I want to use a part of this script here.

function UploadPNG () {
// We should only read the screen bufferafter rendering is complete
yield WaitForEndOfFrame();

// Create a texture the size of the screen, RGB24 format
var width = Screen.width;
var height = Screen.height;
var tex = new Texture2D (width, height, TextureFormat.RGB24, false);
// Read screen contents into the texture
tex.ReadPixels (Rect(0, 0, width, height), 0, 0);
tex.Apply ();

// Encode texture into PNG
var bytes = tex.EncodeToPNG();
Destroy (tex);

// For testing purposes, also write to a file in the project folder
// File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png", bytes);

The lines wich interessed me are :

var bytes = tex.EncodeToPNG();

and

File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png", bytes);

What is the var bytes in C#? I don’t understand what does that represent.

My goal here is to read a Texture2D and save it with a “File.WriteAllBytes” or any other functions which allows me to set the path like here.
All of this is done localy not online.

This is kind of urgent I hope someone can help me quickly

Thank’s a lot

BooBi

“bytes” is referring to a byte array, the line could have been rewritten as:

var bytes : byte[ ] = tex.EncodeToPNG();

Or in C#:

byte[ ] bytes = tex.EncodeToPNG();

I found the solution :wink: thank’s a lot, some times I just need to write my problem in the forum wait few minutes and that’s it ^^

var bytes = tex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + “/…/SavedScreen.png”, bytes);

These two lines can be compiled in C# as is. There are implicitly typed variables in C# 3.0.