Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Script Donation] Health, Mana, Stats, and Class System Script.

Discussion in 'Scripting' started by Wintergrasped, Jun 19, 2014.

?

Used?

  1. Yes

    0 vote(s)
    0.0%
  2. No

    33.3%
  3. Just Looking

    55.6%
  4. Thank You

    11.1%
Multiple votes are allowed.
  1. Wintergrasped

    Wintergrasped

    Joined:
    Dec 14, 2013
    Posts:
    19
    Made yet another Script out of boredum today so here you Go:

    Time Lapse Of Making This Script:
    HERE




    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class SkillSystem : MonoBehaviour {
    5.  
    6.  
    7.     public static int WarriorStam;
    8.     public static int WarriorHealth;
    9.     public static int Warriordamagereduction;
    10.     public static int WarriorIntellect;
    11.     public static int WarriotWisdom;
    12.  
    13.     public static int HunterStam;
    14.     public static int HunterHealth;
    15.     public static int Hunterdamagereduction;
    16.     public static int HunterIntellect;
    17.     public static int HunterWisdom;
    18.  
    19.     public static int KnightStam;
    20.     public static int KnightHealth;
    21.     public static int Knightdamagereduction;
    22.     public static int KnightIntellect;
    23.     public static int KnightWisdom;
    24.  
    25.     public static int RougeStam;
    26.     public static int RougeHealth;
    27.     public static int Rougedamagereduction;
    28.     public static int RougeIntellect;
    29.     public static int RougeWisdom;
    30.  
    31.     public static int DruidStam;
    32.     public static int DruidHealth;
    33.     public static int Druiddamagereduction;
    34.     public static int DruidIntellect;
    35.     public static int DruidWisdom;
    36.  
    37.  
    38.  
    39.     public static int Stamina;
    40.     public static int Strength;
    41.     public static int Health;
    42.     public static int Mana;
    43.     public static int Intellect;
    44.     public static int Wisdom;
    45.     public static int HealthRegen;
    46.     public static int ManaRegen;
    47.     public static int armor;
    48.     public static int curHealth;
    49.     public static int curMana;
    50.     public static int ManaRegenAmount;
    51.     public static int HealthRegenAmount;
    52.     public static int damage;
    53.     public static int damagereduction;
    54.     public static bool EconomyEnabled = true;
    55.     public static int balance;
    56.     public static int interest;
    57.     public static int billamount;
    58.     public static int income;
    59.     public static int depositammount;
    60.     public static int manacost;
    61.     public static bool Dead = false;
    62.     public string CharClass = null;
    63.     public static int healamount;
    64.  
    65.     // Use this for initialization
    66.     void Start () {
    67.  
    68.         RepeatingCalls();
    69.         ApplyStats();
    70.         SetClassStats();
    71.     }
    72.    
    73.     // Update is called once per frame
    74.     void Update () {
    75.    
    76.     }
    77.  
    78.     void RepeatingCalls () {
    79.         invokeRepeating("RegenHealth", 0, 5);
    80.         invokeRepeatinf("RegenMana", 0, 5);
    81.     }
    82.  
    83.     void ApplyStats () {
    84.         Health += Stamina;
    85.         Health += Wisdom;
    86.         Mana += Intellect;
    87.         Mana += Wisdom;
    88.         damagereduction += Strength;
    89.         damagereduction += Intellect;
    90.         debug.log("Total Health"+Health);
    91.         debug.log("Total Mana"+Mana);
    92.         debug.log("Total");
    93.     }
    94.  
    95.     void ApplyDamage () {
    96.         damagereduction -= Strength;
    97.         damage -= damagereduction;
    98.         Health -= damage;
    99.  
    100.     }
    101.  
    102.     void WithDrawlFromBalance () {
    103.         if (balance => billamount) {
    104.             balance -= billamount;
    105.         }
    106.     }
    107.  
    108.     void DepositToBalance () {
    109.         balance += depositammount;
    110.     }
    111.  
    112.     void CastSpell () {
    113.         if (curMana => manacost) {
    114.             if (curHealth => 1) {
    115.  
    116.                 curMana -= manacost;
    117.  
    118.             }
    119.         }
    120.     }
    121.  
    122.     void AntiNegativeMana () {
    123.         if (curMana < 0) {
    124.             curMana = 0;
    125.  
    126.         }
    127.     }
    128.  
    129.     void AntiNegativeHealth () {
    130.         if (curHealth < 0) {
    131.             curHealth = 0;
    132.             Death();
    133.         }
    134.     }
    135.  
    136.     void Death () {
    137.         if (curHealth <= 0) {
    138.             Dead = true;
    139.             curMana = 0;
    140.         }
    141.     }
    142.  
    143.     void TakeDamage () {
    144.         damage -= damagereduction;
    145.         curHealth -= damage;
    146.     }
    147.  
    148.     void SetClassStats () {
    149.         if (CharClass == Warrior) {
    150.             Stamina = WarriorStam;
    151.             damagereduction = Warriordamagereduction;
    152.             Health = WarriorHealth;
    153.             Intellect = WarriorIntellect;
    154.             Wisdom = WarriotWisdom;
    155.         }
    156.         if (CharClass == Archer){
    157.  
    158.     }
    159.         if (CharClass == Hunter) {
    160.  
    161.             Stamina = HunterStam;
    162.             Health = HunterHealth;
    163.             Intellect = HunterIntellect;
    164.             Wisdom = HunterWisdom;
    165.  
    166.         }
    167.         if (CharClass == Rouge) {
    168.  
    169.             Stamina = RougeStam;
    170.             damagereduction = Rougedamagereduction;
    171.             Health = RougeHealth;
    172.             Intellect = RougeIntellect;
    173.             Wisdom = RougeWisdom;
    174.  
    175.         }
    176.         if (CharClass == Druid) {
    177.  
    178.             Stamina = DruidStam;
    179.             damagereduction = Druiddamagereduction;
    180.             Health = DruidHealth;
    181.             Intellect = DruidIntellect;
    182.             Wisdom = DruidWisdom;
    183.  
    184.         }
    185.         if (charClass == Knight) {
    186.  
    187.             Stamina = KnightStam;
    188.             damagereduction = Knightdamagereduction;
    189.             Health = KnightHealth;
    190.             Intellect = KnightIntellect;
    191.             Wisdom = KnightWisdom;
    192.         }
    193.  
    194.        
    195. }
    196.  
    197.     void HealSpell () {
    198.         if (curMana > manacost) {
    199.             if (curHeath < Health) {
    200.                 curmana -= manacost;
    201.                 Health += HealAmount;
    202.             }
    203.     }
    204. }
    205. }
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    Please, do not hard-code your character's class stats. It makes maintenance an horror.
     
    Loius likes this.
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    First thing's first: You should learn to use classes.

    Code (csharp):
    1.  
    2. public class ClassStats {
    3. public string name = "Knight";
    4. public int stamina;
    5. public int damageReduction;
    6. public int health;
    7. public int intellect;
    8. public int wisdom;
    9. }
    10.  
    And now, with an array of ClassStats objects, you can do all sorts of convenient things you could never do with your script.

    Second (related), as LightStriker said, don't hard-code values. You should not be using static variables the way you are using them.

    Thirdly, with as hard-coded as this script is, how do you expect it to be useful to anyone but you? Why would you donate this?

    Finally... there's no way this script compiles as written.
     
    User340 likes this.
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    StarManta, I would put that ClassStats as a ScriptableObject, so I could add a new class to the game anytime I want without modifying any code.
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Oh, I forgot to add the [System.Serializable] tag on it to allow it to be edited in the inspector.
     
  6. Loius

    Loius

    Joined:
    Aug 16, 2012
    Posts:
    546
    Rouge?