x


pop up image from trigger object

Hi,

I'm trying to pop up an image from OnTriggerEnter with box colider trigger. How do I make it work? I've tried these scripts from an Ben Pitt answer but it won't work:

function Update () {
    Hide();
}

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

function Show(paper : Paper) {

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

function OnTriggerExit(otherCollider : Collider) {
    Hide();
}

this one on a GuiTexture

and then:

var popupTexture : Texture2D;
private var paperPopup : PaperPopup;

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

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

function OnTriggerEnter(otherCollider : Collider) {
    paperPopup.Show(this);
}

this script I've puted on a trigger object

Can anyone help?

more ▼

asked May 05 '12 at 08:14 PM

ruimobp gravatar image

ruimobp
0 2 3 3

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I found out the problem: the GUItexture starts off and it won't turn ON when triggered. But the texture changes.

more ▼

answered May 06 '12 at 11:47 AM

ruimobp gravatar image

ruimobp
0 2 3 3

(comments are locked)
10|3000 characters needed characters left

Try this on the object that collides:

private var paperPopup : PaperPopup;

function Start () {
    paperPopup = FindObjectOfType(PaperPopup);
    if (paperPopup)
      paperPopup.renderer.enabled = false; // hide
}

function OnTriggerEnter(otherCollider : Collider) {
    if (paperPopup)
      paperPopup.renderer.enabled = true; // show
}

You might want to implement OnTriggerExit to turn it off again.

Be sure you read this: http://unity3d.com/support/documentation/ScriptReference/Collider.OnTriggerEnter.html If all those conditions aren't met, it won't work. You may want OnColliderEnter instead.

more ▼

answered May 05 '12 at 08:23 PM

DaveA gravatar image

DaveA
26.4k 151 171 256

Didn't work... I'm trying this code only on the trigger but it still won't work: function Update () { Start();

}

var image:GUITexture;

function Start() { image.enabled = true;

}

function OnTriggerEnter(other : Collider) { image.enable = false;

    }

function OnTriggerExit(otherCollider : Collider) { image.enable = true; }

May 06 '12 at 06:48 PM ruimobp

Did I read that correctly, that Update is calling Start, and Start is setting image.enabled to true?? Wow. No. You don't need Update here at all.

May 07 '12 at 02:40 AM DaveA
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x980
x476
x58

asked: May 05 '12 at 08:14 PM

Seen: 755 times

Last Updated: May 07 '12 at 02:40 AM