create a GUITexture through script

how can I create a GUITexture through script with Texture2D where Texture was assigned from the Editor?

using UnityEngine; using System.Collections;

public class Menu : MonoBehaviour {

public Texture2D btnTexture;

public void Start () { buttons[0] = Instantiate(btnTexture, new Vector3(0.5f ,0.5f, 1.0f), Quaternion.identity) as GUITexture; }


and the above code is not working....

How can I succeed it?

btnTexture is a Texture2D, which you cannot cast to a GUITexture. You should be able to do this instead, I think:

buttons[0]=new GUITexture();
buttons[0].transform.position=new Vector3(0.5f ,0.5f, 1.0f);