I have image to load in the scene and i have used texture2d to load the image.But the image is not loading in the screen. I have another button called but the button is loading.
void OnGUI() {
Texture2D texture = Resources.Load("spino2") as Texture2D;
GUI.skin.button = startbtnstyle;
if(GUILayout.Button("Start", startbtnstyle)){
Application.LoadLevel("25Nov1");
}
}
2 Answers
2
I wonder why you store that in “texture” and not using it at all. Since you use the guistyle to draw the button.
Assuming you got the name right, you are loading the image, but you are going to have to select a method of displaying the image. Partial list:
- Use OnGUI() and GUI.DrawTexture()
- Put a material on a Quad, then assign the texture you loaded to renderer.material.mainTexture.
- Create a game object with a GUITexture component and assign the texture to guiTexture.texture.
So from where you are now, the first is the easiest. I suggest you do it this way:
Texture2D texture;
void Start() {
texture = Resources.Load("spino2") as Texture2D;
}
void OnGUI() {
GUI.DrawTexture(new Rect(100,100,500,500), texture);
GUI.skin.button = startbtnstyle;
if(GUILayout.Button("Start", startbtnstyle)){
Application.LoadLevel("25Nov1");
}
}
button is different and the background image is diff..The spino2 is the name of the image
– kartheesok...how to load the image in the scene
– karthees