loading a picture in unity

hi all,
well i’m new in unity, i have a picture and i want to load it in screen and show it when a button is pressed, i need its script.

thank you.
with all regards (: .

Take a look at the documentation related to loading images:

http://docs.unity3d.com/ScriptReference/Texture2D.LoadImage.html

1 Like

thank you for your answer,
i want to know if i want to use these scripts do i need any thing else , any layer any texture any sprite to load on them, cause i tried these scripts (specially the second and third one) but they didn’t work.

excuse me for my request is it possible to make any video tutorial for this? :\ i searched in internet but there isn’t even one video about it.
thank you again.
with all regards (:

Yes, you’ll need to do something like have a GUITexture and set it’s texture member from the image you download.

1 Like

hi, thank you for you answer.
how can i set this texture as member of that image by script before it be downloaded !?
thank you again.
with all regards (:.

So, usually you’d add a GUITexture game object into your scene. You can set the texture on that GUITexture to be any texture you have in your project. By default it’s a Unity logo or something (I forget). Then, in script, you need to have a connection to this GUITexture. You’d do that with something like:

var gt : GUITexture;

This means that you can drag and drop your GUITexture onto the slot that appears in the inspector - just select the GameObject that has your script on it. Now you have a variable that links to your GUITexture. Once the WWW request completes you can do something like:

gt.texture = WWW.texture;

You’ll probably want to do some background research on these topics.

1 Like

thank you for your answer,
well, i did it as the same that told. but it still doesn’t work.
here is my code:

using UnityEngine;
using System.Collections;

public class onClickEvent : MonoBehaviour {
    public string url = "file://C:/Users/Alone/Documents/New Unity Project 9/image.png";
    void OnClick(){
                Application.CaptureScreenshot ("image.png");
                loadImage ();
                }
    private GUITexture gt;
    IEnumerable loadImage(){
               WWW www = new WWW(url);
                yield return www;
                gt.texture = www.texture;
                   
    }

        }

Instead of Using “Application.CaptureScreenshot” just use RenderTexture and convert that RenderTexture to Texture2D and set as a texture of an object.

1 Like

hi, thank you UnityCoder, i would be really glad if you say how to do it … ?

below is the for same:

Modify code as per your requirement.

1 Like