• 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 11, 2014 at 08:08 AM · gameshopin

In-Game Shop Problems

Hi guys,Thanks for clicking and looking into this topic.I am quite stuck on implementing an in-game shop into my game since yesterday.But here's my problem now.

I am using this script for my shop

 private void Shop(Rect position, Buyable buyable)
     {
     if(GUI.Button(new Rect(0,375,128,32),"Back"))
     {
     ToMenu("Main");
     }
         {
             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();
         }
 
     }

     Rect rectangle = new Rect(100,150, 150, 100);
     Buyable buyableItem = new Buyable(); 
 


A list for editing the shop in editor

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

The problem is now is that it doesnt work.Here's a screenshot of what i get.

alt text

No matter how many elements i add into the List(in editor)it doesnt show up the number of elements i put in editor.And if i put 0 elements it shows up.

I want it to look like this .

alt text

And for every element i add in editor,there will be another one with the 2d texture and name i assign in editor a few pixels away.Like the shop and play will replace with all the cars i put in editor.

picture.png (6.4 kB)
picture1.png (51.7 kB)
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

Answer by PAHeartBeat · Sep 11, 2014 at 11:45 AM

Hi Albert,

First Of-all your class should be Serialzable to show in unity editor inspactor. after that you can create a variable of as List or array to edit in editor mode.

Second in your GUI Layout you make only two buttons, I thought you have also use GUI.BeginColomn and GUI.EndColumn to make left-right view of your GUI buttons.

you can achive it using for loop for. and put this code in between of GUI.BeginColumn and GUI.EndColumn in-side of for loop

 if (GUILayout.Button(iconButtonLabel))
 print ("you clicked the icon");
  
 if (GUILayout.Button(textButtonLabel))
 print ("you clicked the text button");
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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

In Game Shop 2 Answers

How to make an ingame weapon/ammo shop 0 Answers

Character shop 0 Answers

Enemies Problem 1 Answer

PayPal in Game Buy 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges