Trying to pick up and see paper - pop up GUI window to examine objects when clicked

Hey, I'm trying to make it so that when you click on an object in the scene (like for example to pick up a piece of paper) it pops up on the screen and shows a graphic texture (for example, showing what the paper says), then click like "EXIT" and go back to the game.

Javascript would be helpful thanks.

Edit:

The answer here is suitable for any system where you would like to click on a gameobject and have it display an image in front of the camera view - either a magnified version of the texture on the gameobject itself (eg, if you clicked on a painting on a wall, you get a close-up view), or an entirely separate image (eg, if you clicked on an information button, a help window could be displayed)

This could be a fairly simple way of implementing this. It simply makes a GUITexture appear on the screen when a "paper object" is clicked, showing the texture of your choice. Another click on the popped-up texture itself makes it dissappear.

1) Create a new "GUI Texture" GameObject (from the gameobject menu). Name it "Paper Popup".

2) Set the texture (using the dropdown) to "None".

3) Create a new Javascript Script, name it "PaperPopup" (it's important to get that name exactly right because it's referenced in the 2nd script). Paste this into it:

function Start() {
    Hide();
}

function Hide() {
    guiTexture.enabled = false;
}

function Show(paper : Paper) {

    if (!guiTexture.enabled) {
        var t = paper.popupTexture;
        var rect = Rect( -t.width/2, -t.height/2, t.width, t.height );
        guiTexture.pixelInset = rect;
        guiTexture.texture = t;
        guiTexture.enabled = true;
    }   
}

function OnMouseUp () {
    Hide();
}

4) Drag that script from your project pane onto the GUITexture Gameobject you just made in the hierarchy.

5) Create another new Javascript script, and name it "Paper" (again, it's important to get that name exactly right because it's referenced in the 1st script).This script should go on each separate piece of paper. You might want to make a prefab paper object, with this script attached, and then create instances of that for each piece of paper in your game.

var popupTexture : Texture2D;
private var paperPopup : PaperPopup;

function Start () {
    paperPopup = FindObjectOfType(PaperPopup);

    if (popupTexture == null) {
        popupTexture = renderer.material.mainTexture;   
    }
}

function OnMouseDown () {
    paperPopup.Show(this);
}

6) Create your pieces of paper objects around your scene. You can set the "popupTexture" variable on each piece of paper to whatever texture you'd like it to show when clicked, or you can leave it unassigned to have it pop up with the actual same texture used on the surface of the paper object.

7) That should be it! Hit play and test your game!

I used "OnMouseDown" for clicking on the paper objects, and "OnMouseUp" for dismissing the popup, as a simple way of avoiding problems where the cursor may be over both the popup and the obscured original paper object at the same time (because using OnMouseUp for both of these can mean that the paper is immediately popped up again by the same event).

Hi,

I need to do this interaction but with a trigger instead of clicking. I’ve tried to put this script with a OnTriggerEnter but it doesn’t work. What am I doing wrong? I just changed the OnMouse on both, and put the “paper” on a box collider trigger.
Can anyone help me?

Hi,

I’m trying to make the same but with box colider trigger. changed this script OnMouse codes for OnTriggerEnter, but nothing works. I’ve puted the pepaer script on a box collider trigger. Can anyone help, please?