• 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
Question by swimfly706 · Oct 26, 2013 at 06:43 PM · buttontexture2dpopupnext

Texture2d Array with Next Button

Hi everyone,

I'm new to Unity and using it for a graduate school project to create a scene based on a book. What I'm trying to do is create an array of several texture2ds (about 100) with a next and previous button so you can examine the textures like you would be flipping through a book. Right now my code is that I have a texture2d that pops up when you click on the book object, but I can't figure out the array. I'd really appreciate any help. Thanks!

Comment

People who like this

0 Show 4
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 26, 2013 at 06:56 PM 0
Share

This appears to be a follow on to your previous question:

http://answers.unity3d.com/questions/553227/how-to-assign-multiple-popup-textures-to-game-obje.html

To display that many images, you don't want to use an array. The code I posted for that question that dynamically loads images from Resources is a good solution. I see reading that last question you asked a follow-up that I missed...probably because the question had already been marked as 'Answered'. Before you go further with your project, I'd like you to verify the code I posted. Try this:

  • Start a new scene

  • Create a Quad (Game Object > Create Other>Quad) at the origin..

  • Resize the Quad to a reasonable size for a page.

  • Create a material using Unlit/Texture for the shader and some graphic for the texture

  • Put your pages in the Resources folder as indicated in the last question

  • Add the script from my last question to the Quad

  • Run the app

You should be able to click on the quad and move forward in the book. This is to verify that you have a setup that works to load pages. Once you have that working, I (or anyone else) can answer how to modify the script to use some buttons rather than a click on the object to move from page to page.

avatar image swimfly706 · Oct 26, 2013 at 07:22 PM 0
Share

Thank you so much for your attention to this! I did what you said and it works. What I really want is for the pages to popup or magnify on the screen when you click on the quad (I think you know this already). Once we get the buttons to work and everything, is it possible to have this texture popup?

avatar image robertbu · Oct 26, 2013 at 08:10 PM 0
Share

Unity Answers is about us helping you solve your own problem. Plus this is a school assignment. When I get back to my computer this evening, I'll give you an updated script that can be hooked up to buttons to go to the next and previous page. In the meantime you should work on getting buttons to display. The easiest way is to use he GUI system. There are many posts and lots of documentation. There are other, more flexible ways to create buttons, but they will involve more work in getting them to work with your page code. Figure out what you want do, then as a start just get them to execute Debug.Log() statements for 'Next' and 'Previous'.

http://docs.unity3d.com/Documentation/Components/gui-Basics.html

As for causing your page to popup, this is not too difficult, but it is a new technical issue that should be asked as a new question. You need to research the issue and then be very explicit about the popup. Does it happen all at once or does it happen over time? What dismisses the popup? What kind of motion is involved...a simple translate or a translate and a rotation? You might experiment with Unity's Animations. Even if you solve your problem in code at the end, an animation that show what you are trying to accomplish is better than any written description.

avatar image swimfly706 · Oct 26, 2013 at 09:33 PM 0
Share

Thanks! I'm experimenting with buttons now but, for my purposes, I'm prioritizing that under getting the pages to popup. I used the code from the answer on this page: http://answers.unity3d.com/questions/15438/trying-to-pick-up-and-see-paper-pop-up-gui-window.html --I want it to do exactly that--if you click on the book the first page should popup and then (using your buttons) you can go to the next one. The popup I have now is activated onmousedown and you can click on the page that pops up to dismiss it. Does that make sense?

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by robertbu · Oct 27, 2013 at 02:37 PM

Here is some modifications to the code from your last question. Call NextPrevPage(true) to go to the next page, Call NextPrevPage(false) to go to the previous page. Replace this script with the one you use to text the Quad as outlined by my comments.

 #pragma strict
  
 var baseName = "Page";
 private var page = 0;
 var lastPage = 100;
  
 function NextPrevPage(nextPage : boolean) {
     var currPage = page;
     
     if (nextPage) {
         if (page + 1 > lastPage)
             return;
         page++; 
     }
     else {
         if (page - 1 < 0)
             return;
         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);
     }
     else {
         page = currPage;
     }
 }
 
 function OnGUI() {
     if (GUI.Button(Rect(0,0,100,50),"Next"))
         NextPrevPage(true);
     if (GUI.Button(Rect(0,75,100,50), "Prev"))
         NextPrevPage(false);
 }
Comment

People who like this

0 Show 8 · 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 27, 2013 at 05:14 PM 0
Share

Great, thank you so much. If I have the popup code, do I incorporate your code into that one so that the next/prev buttons will correspond with the page popups?

avatar image swimfly706 · Oct 27, 2013 at 05:23 PM 0
Share

Or should I create a gui window that pops up where you can see the chapters of the book?

avatar image robertbu · Oct 27, 2013 at 05:32 PM 0
Share

The code at the link you provided uses a GUITexture. This is different from displaying a texture on a Quad. The changes are relatively small. Instead of assigning the texture to the renderer.material.mainTexture, you need to assign the material to the guiTexture.texture. Depending on your use, you may or may not have to merge the scripts, but you do have to change the above script to deal with the GUITexture if you want to use both.

avatar image swimfly706 · Oct 27, 2013 at 05:36 PM 0
Share

You are the best. Thanks.

avatar image swimfly706 · Oct 28, 2013 at 03:18 AM 0
Share

Is there a way to hide these buttons until i click on my book?

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Hair and Skin Color Buttons 0 Answers

How do I Define the Size of a Texture Inside GUI.Button? 0 Answers

popup message with a button 0 Answers

Assiging an Image to a Button 1 Answer

Create a simple image from Vector3 points 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