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
0
Question by Scott 2 · Mar 05, 2010 at 11:54 PM · texturemenuimage-effects

How do I change textures at a click of a button

Hi basically I stumped I am trying to have a menu or layout that allows there to be an image (texture or icon) load within the window and text on another part explaining the image.

So button one shows image one and text for image one, button two shows image two and text for image two and so on.

For the most part I have worked around some of the layout issues (in around about way) but can't change the textures on the click of the button.

Please be gentle I am new (3 weeks) and I am a not a programmer so I am up to my chest in water at the moment. Ta

This is what I am using at the moment:

Screen.lockCursor = false;

GameObject.Find("FPC").GetComponent("MouseLook").enabled = false; GameObject.Find("FPC").GetComponent("Crosshair").enabled = false;

Time.timeScale = 0;

/ Button Content examples / var img1 : Texture2D; var img2 : Texture2D; var img3 : Texture2D; var img4 : Texture2D; var img5 : Texture2D; var img6 : Texture2D;

var windowRect : Rect = Rect (175, 150, 600, 600);

function OnGUI () {

windowRect = GUI.Window (0, windowRect, WindowFunction, "SCOTT'S BOOK:");

}

function WindowFunction (windowID : int) { // Draw any Controls inside the window here

if (GUI.Button (Rect (1,16,598,400), img1)) {
    print ("you clicked the img");
}

if (GUI.Button (Rect (1,434,598,145), "ARTISTS NOTES:\n\n We are please to reveal to you a unique experiencing in online photographic exhibition.....\n\n Blah Blah checking code annd new line works", "button")) { print ("you clicked the icon"); }

if (GUI.Button (Rect (1,415, 100, 20), "img1", "button")) { print ("img1"); }

if (GUI.Button (Rect (99,415, 100, 20), "img2", "button")) { print ("img2"); }

if (GUI.Button (Rect (199 ,415, 100, 20), "img3", "button")) { print ("img3"); }

if (GUI.Button (Rect (299 ,415, 100, 20), "img4", "button")) { print ("img4"); }

if (GUI.Button (Rect (399 ,415, 100, 20), "img5", "button")) { print ("img5"); }

if (GUI.Button (Rect (499 ,415, 100, 20), "img6", "button")) { print ("img6"); }

if (GUI.Button (Rect (1,579, 597, 20), "Close", "button")) { print ("you closed the window");

Destroy (this);

         Time.timeScale = 1;

GameObject.Find("FPC").GetComponent("MouseLook").enabled = true; GameObject.Find("FPC").GetComponent("Crosshair").enabled = true;

gameObject.AddComponent ("LockCursorNew");

Screen.lockCursor = true;

 }

}

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 Lipis · Mar 06, 2010 at 03:08 AM 0
Share

@Scott, You probably noticed that the whole code of your post looks kinda weird.. right?

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Kitty · Mar 09, 2010 at 05:31 PM

I'm still a bit of a noob to scripting, but hopefully this should help you to get your click texture change. If nothing else, get you started.

var normalTexture : Texture 2D; var rollOverTexture : Texture 2D;

function OnMouseEnter(){guiTexture.texture = rollOverTexture;}

function OnMouseExit(){guiTexture.texture = normalTexture;}

As for what you have above for your buttons, you might want to look into GUILayout scripts. Unity's site has a great script reference and it's come in handy many times.

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 lowbloodsugar · Mar 07, 2010 at 05:11 AM

If you are not a programmer you should first learn how to code before getting yourself into a position where you need to code to solve a problem.

There are many books, websites, and schools that teach programming. Some even teach programming with an emphasis on game design. Start there young Jedi. Be patient and the your path will become clear.

If you can't do that that you should consider hiring a programmer to help you.

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 GearWorker · Feb 02, 2011 at 09:35 AM 1
Share

What kind of answer is that? You gotta start somewhere... might as well just jump at it! :)

avatar image qinghill · Dec 27, 2011 at 03:14 AM 0
Share

that guy must be a programmer with no job because graphic designers now lear to do scripting by ourself.. yeah!

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

1 Person is following this question.

avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

How to make a half 2d- half 3d main menu?? 1 Answer

Unity Main Menu 1 Answer

How to place/add a HD image/picture in background of my game? 0 Answers

What does a quad look like? 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