public void AddAttack(UIChoosable attack) { if (ApUsed < MaxAp && (ApUsed + attack.getApCost()) <= MaxAp) { GameObject attackBarUI = Instantiate(AttackBar, this.transform); RectTransform attackBarRT = attackBarUI.GetComponent <RectTransform>(); attackBarRT.anchoredPosition = CalcLocation(ApUsed, attack.getApCost()); AttackBars.Add(attackBarUI); attackBarUI.GetComponent <Text>().text = attack.getName(); attackBarRT.sizeDelta = new Vector2(attackBarRT.rect.width * attack.getApCost(), attackBarRT.rect.height); attacks.Add(attack); ApUsed += attack.getApCost(); } }
public void RemoveFirstAttack() { removeAttack(0); int x = 0; int apUsed = 0; foreach (GameObject attackBarUI in AttackBars) { UIChoosable attack = attacks[x]; RectTransform attackBarRT = attackBarUI.GetComponent <RectTransform>(); attackBarRT.anchoredPosition = CalcLocation(apUsed, attack.getApCost()); apUsed += attack.getApCost(); x++; } }
private void removeAttack(int location) { if (attacks.Count > 0) { UIChoosable toBeRemovedAttack = attacks[location]; ApUsed -= toBeRemovedAttack.getApCost(); attacks.RemoveAt(location); GameObject attackBarUI = AttackBars[location]; AttackBars.RemoveAt(location); Destroy(attackBarUI); } }