public void SetUnit(BaseUnit unit) { CharacterName.text = unit.UnitName; CharacterHP.text = unit.GetActualHP() + "/" + unit.MaxHP; float ratio = (float)unit.GetActualHP() / unit.MaxHP; HPBar.fillAmount = ratio; // Change HP sprite based on level if (ratio < 0.33) { HPBar.sprite = HPBars[0]; } else if (ratio < 0.66) { HPBar.sprite = HPBars[1]; } else { HPBar.sprite = HPBars[2]; } SetThreatIcon(unit.Threat); // Update status icons List <BaseStatus> statuses = unit.Statuses; string[] descriptions = new string[statuses.Count]; Sprite[] sprites = new Sprite[statuses.Count]; for (int i = 0; i < statuses.Count; i++) { descriptions[i] = statuses[i].GetDescription(); sprites[i] = statuses[i].Icon; } SetStatusIcons(sprites, descriptions); }
public void Play(int tile) { // Version with a tile target // TODO probably refactor both methods into a more compact way if (cardData.RequireTarget) { // Check if valid tile if (tile < 0) { Debug.Log("no targets, canceling drag."); GetComponent <CardDragHandler>().CancelDrag(); } else if (_resourceManager.SpendResources(resourceCost, owner)) { Debug.Log("Playing: " + title + " to tile: " + tile); // Send event to global GlobalsManager.Instance.ApplyCardPlayed(owner.IsPlayer(), cardData); foreach (Effect effect in effects) { bool applied = false; if (ApplySelfEffect(effect)) { applied = true; } // Check to see if effect was already applied if (!applied) { if (owner.GetActualHP() > 0) { // Owner of this card is alive ApplyToTile(tile, effect); } else { // Owner of this card is dead goto endEffectLoop; } } } // Resume endEffectLoop: if (transform.parent) // Added check in case the card belong to AI, so no GO { // Player card Hand hand = transform.parent.GetComponent <Hand>(); if (hand != null) { hand.Remove(this); } } else { //Remove enemy card upon playing Destroy(gameObject); } CheckOnPlayRemovalConditions(owner); } } }