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 Dax65 · Feb 11, 2014 at 10:33 PM · menuclick objects

How can I change the texture of a game object by clicking on another game object?

Hello,

I am trying to make a menu that is setup like a journal where you click on a cube and it changes the texture of a plane to the next page. The only problem is I have no clue how to do it.

I just started working with Unity so thanks for your 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

1 Reply

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

Answer by robertbu · Feb 11, 2014 at 10:51 PM

Here is a bit of code to get you started. You attach it to the cube, then in the inspector you need to drag and drop the game object that will be used to display the pages onto the 'pagesGameObject' variable. You will also have to set the size and drag the textures for each page onto the 'pages' variable.

Note if you are going to create more controls for your pages beyond just next page, you will need to split out the page handling script into its own script attached to the pages game object. Then you will need to learn how to communicate between game objects. One way is described here:

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

 #pragma strict
 
 var pagesGameObject : GameObject;
 var pages : Texture[];
 private var currPage = 0;
 
 function Start() {
     pagesGameObject.renderer.material.mainTexture = pages[currPage];
 }
 
 function OnMouseDown() {
     currPage = (currPage + 1) % pages.Length;
     pagesGameObject.renderer.material.mainTexture = pages[currPage];
 }


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 Dax65 · Feb 11, 2014 at 11:09 PM 0
Share

Thank you, this will work for one of my menus but I have another one where I have a corresponding cube for each page. Such as cube1 takes you to the about page and cube2 takes my to the map page.

avatar image robertbu · Feb 11, 2014 at 11:47 PM 0
Share

In order to allow multiple object to drive your pages, you are going to have to learn about inter-component communication as I've indicated at the link. Think about creating a script that has three public functions: NextPage(), PrevPage(), and GotoPage(pageNum : int). Each of the buttons would communicate to the page game object calling one of these three functions.

avatar image Dax65 · Feb 12, 2014 at 12:51 PM 0
Share

THAN$$anonymous$$ YOU SOOO $$anonymous$$UCH!!!!!!!! It all works!!

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

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

Related Questions

How to change texture of another object by clicking on a object? 0 Answers

Popup Textures for game objects 1 Answer

item pick up menu 1 Answer

Using keyboard to control a dialog/shop 1 Answer

GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced) 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