How to assign an image to the Texture class in script

I have a variable of class Texture and I want to assign an image to it without using the Inspector. I want to assign the image to the class Texture in the actual script. I couldnt find the answer in the documentation. Anyone know how to do this?

You have two choices. If the image file comes form Assets/Resources, you can use Resources.Load().

var tex : Texture = Resources.Load("ImageName") as Texture;

If the file comes from a directory on the machine, or if it comes from the net you can use the WWW class:

var url = "file://C:/someplace/ImageName.png";
var www : WWW = new WWW (url);
yield www;
var tex = www.texture;