Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by DTJ Productions · Apr 18, 2010 at 11:36 PM · guigameobjecttexturemouseclickpop-up

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)

Comment
Add comment · Show 1
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 duck ♦♦ · Apr 20, 2010 at 07:48 PM 0
Share

Edited title, tags and added a sentence in the question body to aid search results - because the answer is applicable to many more situations than the specific example of reading a piece of paper.

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by duck · Apr 19, 2010 at 11:38 AM

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).

Comment
Add comment · Show 10 · 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 DTJ Productions · Apr 20, 2010 at 03:50 AM 0
Share

really good but one prob, the first script has an error at the'

function Show(paper : Paper) {

function Show(paper : Paper) { Assets/PaperPopup.js(9,23): BCE0018: The name 'Paper' does not denote a valid type.

avatar image duck ♦♦ · Apr 20, 2010 at 08:30 AM 0
Share

Ah, sorry I neglected to mention that the 2nd script must be named "Paper"! (I've edited the answer to include this).

avatar image Michael 12 · Feb 22, 2011 at 07:27 PM 0
Share

This is perfect for what I'm trying to do also, only thin is, is that I can still fire my gun when the pop up is open which can be deadly if I have my rocket or grenade launcher selected. Is there a way to freeze the scene while this window is open and disable the gun temporarily so that way yur now wasting anunition just to open and close the window, also as a bonus it would be cool if the background behind the window was out of focus or darkened so that way your attention is on the popup window, $$anonymous$$aybe even a timer to close the window would be cool, anyone know how to do that with this code?

avatar image jadedxoxo · Jan 16, 2012 at 08:59 AM 0
Share

could you translate that to c# please???

avatar image AwsomeRod · Dec 11, 2012 at 01:49 AM 0
Share

i dont get the end on adding them to the apers. on the gameobject paper or what??

Show more comments
avatar image
0

Answer by ruimobp · May 05, 2012 at 08:15 PM

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?

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
avatar image
0

Answer by ruimobp · May 05, 2012 at 08:14 PM

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?

Comment
Add comment · Show 2 · 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 hike1 · Dec 25, 2012 at 05:14 PM 0
Share

That's huge, thank you, here's the package, you have to have the controllers unitypackage installed also

http://dl.dropbox.com/u/102638093/paper_popup.unitypackage 12$$anonymous$$

Having a trigger collider version would be good also, can't always get the mouse cursor in various other projects and kits.

avatar image swimfly706 · Oct 26, 2013 at 10:23 PM 0
Share

What happens if you have multiple texture2ds that you want to show? So I would use your code but then with next and previous buttons see more pages?

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

7 People are following this question.

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

Related Questions

how to call a gameobject in one function(mouse selection) to another function (GUI) 1 Answer

Cube click pop-up menu 0 Answers

Same BackGroung For All Screen Resolution 1 Answer

Problem with texture to reset and re-enter the same texture 0 Answers

Change button texture when its clicked 1 Answer


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