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 darryldonohoe · Oct 16, 2013 at 07:12 AM · guiarrayvariablefloatint

"Talent Tree" global yes/false var and int?

Hi, i have been working on a "simple" exp/skills/lvling script. So far everything is working okay. But right now i want to make a seperate script for a talent tree. But this one is a bit harder, because i do not know how to set it up. I thought of some simple variables. Like:

 var talentPoints : int = 0;
 var talentAvailable : boolean = false;

But even when i started with these i thought it wouldn't work because if you have multiple talents and one is enabled(talentAvailable). Then all would be enabled.

I also had the idea of the possibility spending more points(for example 3) on one talent. Again, thinking that it would not work. Because of the same issue like the enabling i mentioned earlier.

Then there is the method of creating a variable for every talent.(i hope there is an easier method) In that case, for each talent. I would have to set it up like:

 "name"TalentPoint : int = 0;
 "name"TalentAvailable : boolean = false;
 "name"MaxLevel : int = 3;

And that probably x 100.

Maybe you guys know a solution for this? Or what these methods are being called so i can search for examples. (i already searched on google for tutorials this but could not find anything)

I hope someone can help me out with this.

Cheers, Darryl

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
1
Best Answer

Answer by mattssonon · Oct 16, 2013 at 08:25 AM

You could create a Talent class with properties for required talents, required talent points, current level, max level, etc. Something like this:

 public class Talent {
     public string name { get; set;}
     public bool isUnlocked { get; set;}
     public Talent requiredTalent { get; set;}
     public int talentPoints { get; set;}
 }

And then you'd initialize all of your talents one by one:

 void Start() {
     Talent shieldBash = new Talent();
     shieldBash.name = "Shield Bash";
     shieldBash.isUnlocked = false;
     shieldBash.requiredTalent = someOtherTalent;
     shieldBash.talentPoints = 50;    
 }

You could then save these talents in an array or something similar for display in your GUI.

Comment
Add comment · Show 3 · 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 darryldonohoe · Oct 16, 2013 at 01:23 PM 0
Share

Too bad i can't check if it works right now, but here is what i have with your help.

This is the class(still have to edit and add some stuff)class:

public class Talent { public var talentName : String = " "; public var talentIcon : Texture2D; public var isUnlocked : boolean = false; public var maxTalentPoints : int = 3; public var requiredTalent : String = " "; public var talentPosition : Rect; enum Type { attack, support, buff, passive } }

And here is the temporary "Talent Tree"

var talentPoints : int = 0; var talentAvailable : boolean = false; var hasPoint : boolean = false;

var talentPointsSpend : int = 0;

var playerSkills : PlayerSkillSystem; var talents : TalentClasses;

function Start() { playerSkills = gameObject.GetComponent("PlayerSkillSystem"); }

function Update() { if(talentPoints

=

1) { hasPoint == true; } }

function OnGUI()

{ if(GUI.Button(Rect(talents.talentPosition,talents.talentIcon), " ")) { if(hasPoint == true) { talentPointsSpend ++; //GAIN TALENT OVER HERE, direct it to TalentClasses } } }

There are probably some mistakes in the scripts. But this method could be used for something that i want?

Thank you for your answer.

Cheers, Darryl

avatar image mattssonon · Oct 16, 2013 at 01:33 PM 0
Share

Your code is a little hard to read, but yes, that could be the basis for a talent tree.

avatar image darryldonohoe · Oct 16, 2013 at 02:45 PM 0
Share

Thanks! Yeah something went wrong when i used the code snippet.

I'll try it out later today, and will post the results.

Cheers, Darryl

avatar image
0

Answer by darryldonohoe · Oct 18, 2013 at 03:42 PM

I know, that this is not an answer, but i couldn't post it as a comment cause there were to many characters.

Anyway, here is what i came up with thanks to you. It is still very basic, but thats mainly because i haven't decided how i wanted it to work.

But with this layout i can probably make some decent talent trees.

 var talentPoints : int = 0;                        //How many talentPoints the player has
 var maxTalentPoints : int = 50;                    //The maximum talentPoints
 var hasPoint : boolean = false;                    //If the player has a talent point
 var talentPointsSpend : int = 0;                //How many talentPoints the player has spend
 
 var playerSkills : PlayerAttributes;
 
 var talentDatabase : TalentInfo[];                //Containing the talent database
 
 private var talentWindow : boolean = false;        //Check if the talentWindow is open
 
 public class TalentInfo
 {
     public var talentName : String;                //Name of the talent
     public var talentIcon : Texture2D;            //Icon of the talent
     public var isUnlocked : boolean = false;    //If the talent is unlocked or not
     public var talentMax : boolean = false;        //If the max level of the talent is reached or not
     public var talentLevel : int = 0;            //the current level of the talent
     public var maxTalentPoints : int = 3;        //the max level of the talent
     public var requiredTalent : String;            //If the talent needs a required talent
     public var talentDescription : String;        //The description of what the talent does
     public var talentPosition = Vector2;    //The position where the talent would be on the screen
 }
 
 
 function Start()
 {
     playerSkills = gameObject.GetComponent("PlayerSkillSystem");
 }
 
 
 function Update()
 {
     //If the player has at least 1 point, than the var hasPoint is set to true else to false
     if(talentPoints >= 1)
     {
         hasPoint = true;
     }
     else
     {
         hasPoint = false;
     }
     
     //Just for test now, if talent 0 is 
     if(talentDatabase[0].talentLevel >= talentDatabase[0].maxTalentPoints)
     {
         talentDatabase[0].talentMax = true;
     }
     if(talentDatabase[1].talentLevel >= talentDatabase[1].maxTalentPoints)
     {
         talentDatabase[1].talentMax = true;
     }
     
     //When the player presses the T key, the "talent window" pops up, or closes
     if(Input.GetKeyDown("t") && talentWindow == false)
     {
         talentWindow = true;
     }
     else if(Input.GetKeyDown("t") && talentWindow == true)
     {
         talentWindow = false;
     }
 }
 
 
 function OnGUI()
 {
     //if talentWindow is true, a GUI.BeginGroup is set containing a window with the "talent tree"
     if(talentWindow)
     {
         GUI.BeginGroup(new Rect(Screen.width /2 -400,Screen.height /2 -300,800,600));
         
         GUI.Box(new Rect(0,0,800,600), " ")
         
         if(GUI.Button(Rect(15,15,20,20),talentDatabase[0].talentName))
         {
             if(hasPoint == true)
             {
                 if(talentDatabase[0].talentMax == false)
                 {
                     talentPointsSpend ++;
                     talentPoints --;
                     talentDatabase[0].isUnlocked = true;
                     talentDatabase[0].talentLevel ++;
                 }
             }                             
         }
         if(GUI.Button(Rect(15,50,20,20), talentDatabase[1].talentName))
         {
             if(hasPoint == true && talentDatabase[0].talentMax == true)
             {
                 if(talentDatabase[1].talentMax == false)
                 {
                     talentPointsSpend ++;
                     talentPoints --;
                     talentDatabase[1].isUnlocked = true;
                     talentDatabase[1].talentLevel ++;
                 }
             }
         }
         
         GUI.EndGroup();
     }
 }

Anyway thanks again!

Cheers, Darryl

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 mattssonon · Oct 21, 2013 at 07:45 AM 0
Share

That looks good! Please either accept your own answer or $$anonymous$$e as the correct to one, to categorize the question as solved. :)

avatar image
0

Answer by TDFO · Jun 19, 2014 at 02:39 AM

I wrote one a bit early today for an RPG game I'm working on. It depended on boolean statements for whether or not the skill was unlocked or if they had enough skill points.

 var level : int;
 var exp : int;
 var pointsToSpend : int;
 if(exp >= level * 4){
 level = level + 1;
 exp = 0;
 };
 var hasS1 : boolean = false;
 var hasS2 : boolean = false;
 var hasS3 : boolean = false;
 var hasA1 : boolean = false;
 var hasA2 : boolean = false;
 var hasA3 : boolean = false;
 var hasT1 : boolean = false;
 var hasT2 : boolean = false;
 var hasT3 : boolean = false;
 var hasB1 : boolean = false;
 var hasB2 : boolean = false;
 var hasB3 : boolean = false;
 var hasM1 : boolean = false;
 var hasM2 : boolean = false;
 var hasM3 : boolean = false;
 var addS1 = function(){
 if(pointsToSpend >= 1){
 if(hasS1 === false){
 hasS1 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 };
 var addS2 = function(){
 if(pointsToSpend >= 1){
 if(hasS1){
 if(hasS2 === false){
 hasS2 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 }
 };
 var addS3 = function(){
 if(pointsToSpend >= 1){
 if(hasS2){
 if(hasS3 === false){
 hasS3 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 }
 };
 var addA1 = function(){
 if(pointsToSpend >= 1){
 if(hasA1 === false){
 hasA1 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 };
 var addA2 = function(){
 if(pointsToSpend >= 1){
 if(hasA1){
 if(hasA2 === false){
 hasA2 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 }
 };
 var addA3 = function(){
 if(pointsToSpend >= 1){
 if(hasA2){
 if(hasA3 === false){
 hasA3 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 }
 };
 var addT1 = function(){
 if(pointsToSpend >= 1){
 if(hasT1 === false){
 hasT1 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 };
 var addT2 = function(){
 if(pointsToSpend >= 1){
 if(hasT1){
 if(hasT2 === false){
 hasT2 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 }
 };
 var addT3 = function(){
 if(pointsToSpend >= 1){
 if(hasT2){
 if(hasT3 === false){
 hasT3 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 }
 };
 var addB1 = function(){
 if(pointsToSpend >= 1){
 if(hasB1 === false){
 hasB1 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 };
 var addB2 = function(){
 if(pointsToSpend >= 1){
 if(hasB1){
 if(hasB2 === false){
 hasB2 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 }
 };
 var addB3 = function(){
 if(pointsToSpend >= 1){
 if(hasB2){
 if(hasB3 === false){
 hasB3 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 }
 };
 var addM1 = function(){
 if(pointsToSpend >= 1){
 if(hasM1 === false){
 hasM1 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 };
 var addM2 = function(){
 if(pointsToSpend >= 1){
 if(hasM1){
 if(hasM1 === false){
 hasM2 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 }
 };
 var addM3 = function(){
 if(pointsToSpend >= 1){
 if(hasM2){
 if(hasM3 === false){
 hasM3 = true;
 pointsToSpend = pointsToSpend - 1;
 }
 }
 }
 };
 function OnGUI () {
     if (GUI.Button (Rect (100,100,200,20), "Swords Do 20% More Damage")) {
         addS1();
     }
     if (GUI.Button (Rect (100,125,200,20), "Swords Do 30% More Damage")) {
     addS2();
     }
     if (GUI.Button (Rect (100,150,200,20), "Swords Do 40% More Damage")) {
     addS3();
     }
     if (GUI.Button (Rect (310,100,200,20), "Bows Do 20% More Damage")) {
     addA1();
     }
     if (GUI.Button (Rect (310,125,200,20), "Bows Do 30% More Damage")) {
     addA2();
     }
     if (GUI.Button (Rect (310,150,200,20), "Bows Do 40% More Damage")) {
     addA3();
     }
     if (GUI.Button (Rect (520,100,300,20), "20% Harder To Detect While Sneaking")) {
     addT1();
     }
     if (GUI.Button (Rect (520,125,300,20), "30% Harder To Detect While Sneaking")) {
     addT2();
     }
     if (GUI.Button (Rect (520,150,300,20), "40% Harder To Detect While Sneaking")) {
     addT3();
     }
     if (GUI.Button (Rect (830,100,200,20), "Blocking is 20% More Effective")) {
     addB1();
     }
     if (GUI.Button (Rect (830,125,200,20), "Blocking is 30% More Effective")) {
     addB2();
     }
     if (GUI.Button (Rect (830,150,200,20), "Blocking is 20% More Effective")) {
     addB3();
     }
     };
 
     

 
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.

Follow this Question

Answers Answers and Comments

16 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 avatar image avatar image avatar image

Related Questions

GUI.DrawTexture Error & Static Variables!! 2 Answers

Monodevelop is expecting int from my float array 3 Answers

Setting float variable to an Array value 1 Answer

Having a GUI text as a int 3 Answers

i cant make a label show my var Health : int = 100; 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