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 chris gough · Apr 09, 2012 at 10:48 PM · guitexturebuttonstringinventory

how to change a gui button texture

I have an inventory script that creates an a button at the bottom of the screen for the items in the inventory, but I am encountering an issue as it currently simply has text, where as I want a different image in each box.

I have linked the script below to show my issue:

pragma strict

ar obj_wood : GameObject;

var obj_claw : GameObject;

var obj_bread : GameObject;

var obj_water : GameObject;

var numberOfItems : Number;

public var items = new System.Collections.Generic.Dictionary. ();

private var curItem : System.Collections.Generic.KeyValuePair. ;

public var buttonHeight = 50;

public var width = 100;

AddItemToInventory(obj_wood);

AddItemToInventory(obj_claw);

AddItemToInventory(obj_bread);

AddItemToInventory(obj_water);

function AddItemToInventory (item : GameObject) {

  items.Add(item.name, item);
 
  Destroy(item);

}

function OnGUI() { var curIndex = 0;

     GUI.BeginGroup (new Rect (400, 300, 400, 120));

for(var item : System.Collections.Generic.KeyValuePair. in items) {

          var rect : Rect = new Rect((width+2) * curIndex, 0, width, buttonHeight);
 
          var itemTexture : Texture = "icon_"+item.key;

//i have called each texture icon_"item name", but the texture variable wont accept a string

          if(GUI.Button(rect, itemTexture)) {
                curItem = item;
                
               RemoveItem(item);
          }
          curIndex++;
     }

     GUI.EndGroup();

}

function RemoveItem (item : System.Collections.Generic.KeyValuePair. ) {

  yield WaitForEndOfFrame;
 
  items.Remove(item.Key);

}

function RemoveItem (item : GameObject) {

  yield WaitForEndOfFrame;
 
  items.Remove(item.name);

}


if you have any idea of how too this it would be appreciated thank you

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 Aydan · Apr 10, 2012 at 01:11 AM

http://unity3d.com/support/documentation/Components/gui-Customization.html

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 chris gough · Apr 11, 2012 at 01:25 PM 0
Share

thanks found the solution through GUI skins

avatar image gouthammannuru · Oct 28, 2015 at 07:03 AM 0
Share

page notfound

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

6 People are following this question.

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

Related Questions

proper inventory system issue.. 1 Answer

GuiTexture (Touch button) unfollow camera! 1 Answer

GUI Button to create another GUI 1 Answer

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

GUI.button Texture shows up in Unity but doesn't show on android device. 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