- Home /
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?
Answer by Wolfram · Aug 25, 2010 at 04:47 PM
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);
buttons[0].texture=btnTexture;
Thanks.. I will try it in that way.... really appreciate it
Your answer
Follow this Question
Related Questions
Change texture of GUItexture from script 4 Answers
New GameObject with GUITexture is a Horribly Incorrect Size 1 Answer
Floating Health Bars 1 Answer