I am having a problem with a variable thats changing and have no clue why.
I have three buttons with their own script that I activate in a script. The skill class is a scriptable object.
Everything looks good in the inspector and each button gets their respective skill, but when i click on any one of them the skill variable is always the last, for all three of them…
void ShowButtons(List<Skill> chosenSkills)
{
for (int i = 0; i < 3; i++)
{
if (i >= chosenSkills.Count) break;
upgradeButtons_.SetActive(chosenSkills*);*_
}
}
----------
[SerializeField] Skill skill;
public void SetActive(Skill skill)
{
this.skill = skill;
gameObject.SetActive(true);
button.image.sprite = skill.card;
particles.SetActive(skill.isTalent);
SetText(skill.name, skill.description, skill.lvl, false);
}
public void OnClick()
{
IUpgrade upgrade = (IUpgrade)GlobalData.player.AddComponent(skill.script.GetClass());
upgrade.OnBuy(skill.prefabs[0]);
UpgradeManager.instance.AfterClick();
}