I haven’t written code for a long time, and my coding skills are low.
I’m trying to make a bonus to my maximum health when leveling each of the skills. When the total bonus from skills is 20, then my health constantly increases.
And at this moment I can not understand what is happening.
To clarify: there are identical skills, pumping these skills, we add their levels into one variable and thereby get a bonus. And when from all skills the sum of levels is 20 there is a glitch? I don’t understand(
There can be many such skills, they all go to a common bonus
using UnityEngine;
using TMPro;
public class Littel_Skills_Hp : MonoBehaviour
{
public GameManager gM;
public Skills_Hp sH;
public int lvl_Littel_Skill_HP; // lvl Littel Skill
public int price_Littel_Skills; // Cost to increase 1st small HP skill
public TMP_Text lvlSkillText;
private void Start()
{
sH = FindObjectOfType<Skills_Hp>();
gM = FindObjectOfType<GameManager>();
}
private void FixedUpdate()
{
TextButton();
}
public void LvlUpLittelBonusHP()
{
if (lvl_Littel_Skill_HP < 10 & gM.gold >= price_Littel_Skills)
{
gM.gold -= price_Littel_Skills;
lvl_Littel_Skill_HP += 1;
sH.all_Littel_Skills_HP += 1;
price_Littel_Skills += price_Littel_Skills * lvl_Littel_Skill_HP / 5;
Debug.Log(sH.all_Littel_Skills_HP);
}
}
private void TextButton()
{
lvlSkillText.text = lvl_Littel_Skill_HP.ToString();
}
}
Here we have a general bonus from all skills giving an increase to health. base_Bonus_HP I didn’t raise during the tests and it was at zero.
using System.Collections;
using UnityEngine;
public class Skills_Hp : MonoBehaviour
{
public GameManager gM;
public int bonus_HP;
public int base_Bonus_HP; // Large HP skill giving 100 HP for 1 lvl
public int lvl_Base_Bonus_HP = 0; // Large HP skill level
public int price_Base_Bonus_HP = 100; // Cost to increase a large HP skill
public int all_Littel_Skills_HP; // bonus from all small skills, all small skills are summed up here
public int bonus_Littel_Skill_HP; // bonus from the 1st small skill to HP, this bonus is the same for all small skills
private void Start()
{
gM = FindObjectOfType<GameManager>();
}
private void FixedUpdate()
{
bonus_HP = (base_Bonus_HP * lvl_Base_Bonus_HP) + ((gM.maxPlayerHealth / 100) * (all_Littel_Skills_HP * bonus_Littel_Skill_HP));
Debug.Log(bonus_HP);
}
private void LvlUpBaseBonusHP()
{
if (lvl_Base_Bonus_HP < 10 & gM.gold >= price_Base_Bonus_HP)
{
gM.gold -= price_Base_Bonus_HP;
lvl_Base_Bonus_HP += 1;
price_Base_Bonus_HP += price_Base_Bonus_HP * lvl_Base_Bonus_HP;
}
}
}