Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ruimobp · May 05, 2012 at 08:14 PM · triggerguitexturepopup

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ruimobp · May 06, 2012 at 06:48 PM 0
Share

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; }

avatar image DaveA · May 07, 2012 at 02:40 AM 0
Share

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.

avatar image WaiYsky · Nov 23, 2016 at 03:49 AM 0
Share

Can I ask a question here. What is that you used there as "PaperPopup". It is like game object?

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges