Basic Stats and effects (hit, damage, dodge, critical, regen and dps)

Hello community,

I’m new here, and am generally not user forums to avoid questions useless posts.

few hours I am trying to improve this code for a mini personal project, and I am without complete success.

if not begging, some tips would be good. (since I’m starting).

Thank you alot.

using UnityEngine;
using System.Collections;

public class Attributes : MonoBehaviour
{
    public CharacterController controller;

    //Class of player
    public bool Meele;
    public bool Range;
    public bool Mage;

    //Base Stats
    public int BaseSTR;
    public int BaseDEX;
    public int BaseINT;

    //equipament add
    private int equipSTR;
    private int equipDEX;
    private int equipINT;
   
    private int EquipHit;
    private int EquipCrit;
    private int EquipDodge;
    private int EquipHpS;
    private int EquipMpS;

    private int EquipDamage;
    private int EquipDPS;
    private int WeaponSpeed;

    //Sigma
    public int STR;
    public int DEX;
    public int INT;

    //Final Result (public only to see)
    public double hitPorcent;
    public double critPorcent;
    public double DodgePorcent;
    public double HPforSec;
    public double MPforSec;
    public double Damage;
    //public int DamageMin;
    //public int DamageMax;
    public double DamageSpeed;
   
    void Start ()
    {

    }

    void Update ()
    {
        STR = SomaStr(BaseSTR,equipSTR);
        DEX = SomaStr(BaseDEX,equipDEX);
        INT = SomaStr(BaseINT,equipINT);
        Player();
    }

    int SomaStr(int Str, int Strr)
    {
        int STR = Str+Strr;
        return STR;
    }
    int SomaDex(int Dex, int Dexx)
    {
        int DEX = Dex+Dexx;
        return DEX;
    }

    int SomaInt( int Int, int Intt)
    {
        int INT = Int+Intt;
        return INT;
    }
    /*
    void Player()
    {
        if(Meele == true)
        {
            hitPorcent = 65.303+ (DEX * 0.167) + (INT * 0.1); // +hit from equips;
            critPorcent = 1.508 + (STR * 0.03) + (DEX * 0.032) + (INT * 0.02);// + Crit from equips
            DodgePorcent = 1.5025 + (STR * 0.025) + (DEX * 0.0125) + (INT * 0.005);// + Dodge from equips
            HPforSec = 0.8 + (STR * 0.02) + (DEX * 0.01) + (INT * 0.005);// + H/s from equips
            MPforSec = 0.68 + (INT * 0.02);// + M/s from equips
            Damage = (Random.Range (7.35F,13.35F)) + (STR * 0.02) + (DEX * 0.15) + (INT * 0.08);// + Damage from equips //10.35(max+3,min-3)
            DamageSpeed = 7.8741 + (STR * 0.0167) + (DEX * 0.125) + (INT * 0.067);// + (Damage from equips / weapon speed)
        }
    }

    void Player()
    {
        if(Range == true)
        {
            hitPorcent = 65.391 + (DEX * 0.167) + (INT * 0.1);// + Hit% from equips
            critPorcent = 1.472 + (STR * 0.03) + (DEX * 0.032) + (INT * 0.02);// + Crit from equips
            DodgePorcent = 1.4825 + (STR * 0.025) + (DEX * 0.0125) + (INT * 0.005);// + Dodge from equips
            HPforSec = 0.785 + (STR * 0.02) + (DEX * 0.01) + (INT * 0.005);// + H/s from equips
            MPforSec = 0.78 + (INT * 0.02);// + M/s from equips
            Damage = (Random.Range (8.38F,14.38F)) + (STR * 0.02) + (DEX * 0.15) + (INT * 0.08);// + Damage from equips //11.38(max+3,min-3)
            DamageSpeed = 9.5246 + (STR * 0.0167) + (DEX * 0.125) + (INT * 0.067);// + (Damage from equips / weapon speed)
        }
    }
        */
    void Player()
    {   
        double[] varChanger;

        if(Mage == true && Range == false && Meele == false)
        {   
            varChanger = new double[] {65.456};
            varChanger = new double[] {1.496};
            varChanger = new double[] {1.49};
            varChanger = new double[] {0.685};
            varChanger = new double[] {0.78};
            varChanger = new double[] {7.47F};
            varChanger = new double[] {13.47F};
            varChanger = new double[] {8.8143};
        }
        if(Mage == false && Range == true && Meele == false)
        {
           
        }
        if(Mage == false && Range == false && Meele == true)
        {
           
        }

        hitPorcent = varChanger[0] + (DEX * 0.167) + (INT * 0.1);// + Hit% from equips
        critPorcent = varChanger[0] + (STR * 0.03) + (DEX * 0.032) + (INT * 0.02);// + Crit from equips
        DodgePorcent = varChanger[2] + (STR * 0.025) + (DEX * 0.0125) + (INT * 0.005);// + Dodge from equips
        HPforSec = varChanger[3] + (STR * 0.02) + (DEX * 0.01) + (INT * 0.005);// + H/s from equips
        MPforSec = varChanger[4] + (INT * 0.02);// + M/s from equips           
        Damage = (Random.Range (varChanger[5],varChanger[6])) + (STR * 0.02) + (DEX * 0.15) + (INT * 0.08);// + Damage from equips //10.47(max+3,min-3)
        DamageSpeed = varChanger[7] + (STR * 0.0167) + (DEX * 0.125) + (INT * 0.067);// + (Damage from equips / weapon speed)

        varChanger.Clear();
    }

}

What exactly are you trying to do?

That looks very confusing.
You should use more explicit names.
For example, this looks like random text with int, Int, Intt.

 int SomaInt( int Int, int Intt)
    {
        int INT = Int+Intt;
        return INT;
    }

Apart from the fact that a method that adds two values is totally unnecessary.

Further down there is an obvious error, where you create the varChanger multiple times instead of adding values to the same object. It should be:

varChanger = new double[] {
    65.456,
    1.496,
    1.49,
    0.685,
    0.78,
    7.47,
    13.47,
    8.8143
};

And there is no Clear() for an array. The compiler/Editor should have marked that line as an error.

Thanks crafting legends, this resolves the error that was giving. Creativity zero for variable names, but thanks for the tip, I’ll mplement.

Polymorphik, I was thinking in the calculations of stat character, capturing values. lines 62,67,73 adding the stat equipment with basic stat (which will be almentados level by 5 per player).

in summary: entering stat: intelligence, strength and dexterity and output returns: hit, damage, dodge, critical, regen and dps