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 Tristsin · Mar 06, 2013 at 05:20 AM · javascriptgui

Is it possible to link character skill lists to a GUI, and if so, how?

In our game, characters are able to level up, and when they do they are presented with options of some skills to choose from, but not everyone will end up with the same skills(as the option of which skills you want to learn is different for each character/player). My question is, how could I display a list of the skills they have unlocked with their character on a GUI, so that they are able to see the available skills in combat.

Currently my GUIs are all built through the OnGUI function.

I'm not an experienced programmer, so if you could, please explain simply, or at least in a way that I can further research

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by enmeii · Mar 06, 2013 at 06:21 AM

I suggest you buy a plugin which named "NGUI". There are some awesome examples which is like your idea. Talent tree?

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 Tristsin · Mar 06, 2013 at 06:37 AM 0
Share

Looks like a great plugin, and I thank you for the recommendation but I'd prefer to learn how to do it myself. I'm rather new to program$$anonymous$$g, and I need to learn. I've been trying to work out the solution to this for a few days now on my own but have been having trouble, so here I am.

Again, thank you for the recommendation.

avatar image
0

Answer by Chronos-L · Mar 06, 2013 at 05:59 AM

 // I assumed that you have a interface/abstract class called Skill
 // Because you mentioned that not every character has the same skill,
 // so I made this assumption that you are taking this approach.
 public class Skill {
    public string name;

    ...
    ...  
 }
 
 
 public class Example : MonoBehaviour {
    //It doesn't matter as long as it is a collection of skills
    public Skill [] skill;
 
    //You can either leave it as a function or put it in your OnGUI
    private string[] GetSkillName() {
       string [] str = new string[skill.Length];
       
       for( int i = 0; i < skill.Length; i++ ) {
          str[i] = skill[i].name;
       }      
    }
 
    void OnGUI() {
    
       string [] skillName = GetSkillName();
 
       //Display the skills
    
    }
 }

This is a very basic solution, much more work are needed if you need more than displaying a list of skill.

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 Tristsin · Mar 06, 2013 at 06:35 AM 0
Share

Yes, the skill list is basically being listed as an "available actions" type of menu where you choose your skill.

After reading your first comments, I was curious to why you'd assume I'd be using a interface for this so I did a long reading session as I have never used an interface inside any of my other projects(though up until now my projects have all been simple projects).

As a "newbie" to Unity, and program$$anonymous$$g in general there are a lot of things I simply don't know about, I guess you could say.

As you said, your solution is a very basic solution, being that it would only show the skill names, and no functionality to it other than that. I'm not familiar with C#, but from what I'm getting in your OnGUI, it is returning a string of each skill name the skill[] iterates through? How is this being displayed onto the screen though the GUI, just as text?

avatar image Chronos-L · Mar 06, 2013 at 10:38 AM 0
Share

To display the skills as text, you can use GUILayout, GUILayout is automatically aligned & positioned while GUI is manual.

 void OnGUI() {
 
    string [] skillName = GetSkillName();
 
    //$$anonymous$$anually adjust the position/size of the area
    GUILayout.BeginArea(new Rect(10, 10, 100, 100));
    
    foreach( string s in skillName ) {
       GUILayout.Label( s );
    }
    
    GUILayout.EndArea();
 }

$$anonymous$$ore on GUILayout

I am talking about interface because you are doing Skill. Usually skill for different character has different effect/codes, so the norm is to use a interface/abstract class to generalize your skill (name, $$anonymous$$P cost, description etc).

It is even possible to not using a interface/abstract class, then you are looking at delegates, which is quite useful when you need variations in code between objects of the same class.

avatar image
0

Answer by gfvfubb · Mar 06, 2013 at 06:13 AM

So how is it you are storing your skills? In a Dictioary? An Array? What? When the user is presented with the option to level up a skill, what is he doing?

The simplest way to do this is to have a generic skill dictionary or hashtable look up where you save indexes of which skills the player has and then print those indexes out later in the GUI label showing active skills. Or you could just push the skill names to an array if you are really lazy and use .ToString() on the Array.

If you have unique skill objects you can also use dictionary index lookups for them as well instead of having to assign them and call a GetName function as in the other answer.

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 Tristsin · Mar 06, 2013 at 06:27 AM 0
Share

I haven't yet decided which solution would be the best way to store and display my skills. I see you suggest using a dictionary or hashtable.

This might be a bit much to ask, but could you explain the use of a dictionary to store all my skills to me like I'm a child?

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

13 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Items with Statistics(such as attack damage) that actually effect the character? 2 Answers

Sprint Error script? 2 Answers

Need help with my script 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