- Home /
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?
Answer by DaveA · May 05, 2012 at 08:23 PM
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.
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; }
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.
Can I ask a question here. What is that you used there as "PaperPopup". It is like game object?
Answer by ruimobp · May 06, 2012 at 11:47 AM
I found out the problem: the GUItexture starts off and it won't turn ON when triggered. But the texture changes.
Your answer
Follow this Question
Related Questions
Trigger GUI fade 0 Answers
A big problem with my script.. 2 Answers
I want to trigger particle with collectable 2 Answers
Pop up image triggered by box collider? 1 Answer
GUITextures and Triggers 0 Answers