Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Albert-han · Sep 10, 2014 at 10:49 AM · gameshopin

In Game Shop

Hi guys,thanks for looking into this question

I have a problem for an shop i am trying to make for my game.I am using a public List (in editor) to add the cost and stuff.

 public class Buyable
     {
         public string name;
         public Texture2D CharTexture;
         public int Cost;
             public bool Unlocked;
     }

My problem now is how do i use this to create this alt text

with this script

  if (GUI.Button (new Rect (10,10, 100, 50), icon)) {
             print ("you clicked the icon");
         }
     
         if (GUI.Button (new Rect (10,70, 100, 20), "This is text")) {
             print ("you clicked the text button");
         }

like use the (texture 2d) in list to show the texture on the icon and (Name) in list to show the name.

I need to put up a new icon and name for every new element i put in the editor list.I tried to do this my self but i have no idea how to start this and i googled it but no hope.

I tried to explain as detailed as i can.I hope u guys will understand it.Thanks

gsg-iconstringcontent.png (13.8 kB)
Comment
Add comment · Show 2
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 VesuvianPrime · Sep 10, 2014 at 11:39 AM 1
Share

All of my hair just stood up on end. PLEASE don't call your class "Char". There is already a builtin type in C# called char: http://www.dotnetperls.com/char

avatar image Albert-han · Sep 10, 2014 at 11:44 AM 0
Share

Sorry editted,wanted to make it short for character.

2 Replies

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

Answer by VesuvianPrime · Sep 10, 2014 at 11:50 AM

It actually becomes really easy to add textures to buttons when you stop using strings and start using GUIContent to label your GUI:

http://docs.unity3d.com/ScriptReference/GUIContent-ctor.html

Now, we're interested in the GUI.Button overload that takes a GUIContent:

http://docs.unity3d.com/ScriptReference/GUI.Button.html

For example:

 public static void DrawCharGUI(Rect position, Buyable buyable)
 {
     GUIContent iconButtonLabel = new GUIContent(buyable.CharTexture, "Some Tooltip");
     GUIContent textButtonLabel = new GUIContent(buyable.name, "Another Tooltip");
 
     GUILayout.BeginArea(position);
     
     if (GUILayout.Button(iconButtonLabel))
         print ("you clicked the icon");
  
     if (GUILayout.Button(textButtonLabel))
         print ("you clicked the text button");
 
     GUILayout.EndArea();
 }
Comment
Add comment · Show 4 · 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 Albert-han · Sep 10, 2014 at 12:02 PM 0
Share

Thanks,i looked into the gui content but i am not really into that look im more into a big texture ontop and the text below.For example:Hill climb racing.

avatar image Albert-han · Sep 10, 2014 at 12:09 PM 0
Share

Im sorry,im not at my desk and i missread your answer,sorry.Can yiu tell me will this add a picture and text for every element i add in the editor list.

avatar image Landern · Sep 10, 2014 at 01:14 PM 0
Share

@Albert-Han, the method @VesucianPrime provided you could do what you want, but the calling method would have to iterate over your collection(List of type Buyable), other than that, you should give them some upvotes.

avatar image Albert-han · Sep 10, 2014 at 01:25 PM 0
Share

Yep,really sorry vote because i have less than 15 reps,sorry but i choose the best answers thanks.

avatar image
0

Answer by khenkel · Sep 10, 2014 at 11:51 AM

I think you might want to start with the Unity documentation:

GUI Basics Tutorial

GUI.Button reference

I'm sorry for only providing links, but I think writing code for you or extensively explaining how the GUI system works wouldn't really help you. (also since there already are good tutorials)

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 Albert-han · Sep 10, 2014 at 11:59 AM 0
Share

Sorry but i guess you guys misunderstood my question.Sorry for the bad writing.I just wanted it to make one of the textures and button for each element i put in the editor list.I hope this will help you guys.Thanks alot

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

In-Game Shop Problems 1 Answer

Drawcalls in Mobile game 2 Answers

PayPal in Game Buy 2 Answers

InGame Menu (toggle) 2 Answers

Character ShopSave 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