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
0
Question by swimfly706 · Oct 10, 2013 at 06:32 PM · gameobjectpopup2dtextureprops

How to assign multiple popup textures to game objects

So, I'm new to unity and I'm trying to design an educational scene where the user clicks on a game object or prop--something like a letter, a clock, etc--and you can read the pages of a book...so one page pops up and then you can have an arrow that clicks to the next page and so forth. Right now I have a popup code but it only allows for one 2d texture to popup. Any help is appreciated!

 var popupTexture : Texture2D;
 private var paperPopup : PaperPopup;
  
 function Start () {
     paperPopup = FindObjectOfType(PaperPopup);
  
     if (popupTexture == null) {
         popupTexture = renderer.material.mainTexture; 
  
      
     }
 }
  
 function OnMouseDown () {
     paperPopup.Show(this);
 }
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 robertbu · Oct 10, 2013 at 07:04 PM 0
Share

The typical way to solve this problem in unity is by using multiple game objects and communicating between them. That is your arrow and your page would be two different game object. When the arrow was clicked on, it would communicate to the page that it needs to change.

Learning how to communicate between game objects is a frequent question on this list with many answers if you do a search. It can be difficult to figure out he first time, and there are multiple solutions. Here are links on how to access components on other game objects:

http://docs-jp.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

http://docs-jp.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Components.html

An alternate way is to use GameObject.Send$$anonymous$$essage().

1 Reply

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

Answer by robertbu · Oct 11, 2013 at 01:12 AM

There are a couple of concepts to understand here. A game object has a Renderer. A Renderer has a Material. Typically what is displayed is the main texture of that material. You cannot associate all the pages of a book with the material. Typically how you would implement a page change is to change the main texture of the material of that game object. You can associate multiple textures with game object by creating an array in a script. But for your use, I highly recommend something that dynamically loads each page from the Assets/Resources directory and then unload the previously used page. You will avoid memory problems that way. So my suggestion is to:

  • Name all of your pages with a number extension. For example, you can name them 'Page0, 'Page1', 'Page2'...

  • Put your pages in the Assets/Resources directory. It is important that they be placed in this specific directory and that the directory be named with an upper case 'R'.

  • Attach the following script to the Quad that you are using to display the pages:


 private var baseName = "Page";
 private var page = 0;
 
     function OnMouseDown() {
         page++;
         var newPage : Texture = Resources.Load(baseName+page) as Texture;
         if (newPage != null) {
             var lastPage = renderer.material.mainTexture;
             renderer.material.mainTexture = newPage;
             Resources.UnloadAsset(lastPage);
         }
     }

When you click on the page, the Quad will display the next page. You will still have to figure out intra-object communication to get the arrow keys working. And you will have additional code to write to confine the user to only existing pages. But this will show the concept and get your pages up and displaying.

Comment
Add comment · Show 1 · 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 swimfly706 · Oct 13, 2013 at 09:33 PM 0
Share

Ok, this is great, thanks so much--here is what it's doing now, though. I have a prop--a book--in my scene, so my goal was to be able to click on it and see the pages. Right now, after utilizing your code, I can click on it and see one page, but then one of the pictures in my Assets/Resources directory replaces the outside texture of the book but doesn't pop up its content. So basically ins$$anonymous$$d of the pages popping up, one image pops up (like it always did) and then if you click off of it the book changes color (texture) but nothing else pops up. Is this fixable?

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

16 People are following this question.

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

Related Questions

individual object menu 0 Answers

How to pop up a window with image inside when click a game object? 0 Answers

changing Texture on a material of a child object effecting all child game object of that prefab 2 Answers

How to create a simple "Choose the correct answer" script 0 Answers

Dropping a game-object into my armature hierarchy remaps the armature of the model? 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