- Home /
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
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
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
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();
}
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.
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.
@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.
Yep,really sorry vote because i have less than 15 reps,sorry but i choose the best answers thanks.
Answer by khenkel · Sep 10, 2014 at 11:51 AM
I think you might want to start with the Unity documentation:
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)
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
Follow this Question
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