- Home /
How to load image
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");
}
}
Answer by Quaker_SDR · Sep 30, 2014 at 05:58 AM
I wonder why you store that in "texture" and not using it at all. Since you use the guistyle to draw the button.
button is different and the background image is diff..The spino2 is the name of the image
Answer by robertbu · Sep 30, 2014 at 06:13 AM
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");
}
}
it's loading the image but it showing too small..I used 768x1024 for iPad..It's not showing proper
I belive you are aware about the rect.
Portrait: GUI.DrawTexture(new Rect(0,0,768,1024), texture);
Landscape:
GUI.DrawTexture(new Rect(0,0,1024,768), texture);
Your answer
Follow this Question
Related Questions
Image Effects on MovieTexture 0 Answers
load all png files as resource but NOT from resource folder 2 Answers
Images not importing when platform is ios? 0 Answers
How can I add a distance cap to this script? 3 Answers
32 bit color in texture file 0 Answers