diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 4487d9f..c660558 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -35,8 +35,7 @@ public class BattleController : MonoBehaviour heroSprites[i].transform.position = new Vector3(-6 + 6 * i, 0, 0); heroUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); - heroUIs[i].target = heroSprites[i]; - heroUIs[i].battleParticipant = heroes[i]; + heroUIs[i].Init(heroSprites[i], heroes[i]); } monsters = new BattleMonster[3]; @@ -53,8 +52,7 @@ public class BattleController : MonoBehaviour monsterSprites[i].transform.position = new Vector3(-6 + 6 * i, 3, 0); monsterUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); - monsterUIs[i].target = monsterSprites[i]; - monsterUIs[i].battleParticipant = monsters[i]; + monsterUIs[i].Init(monsterSprites[i], monsters[i]); } } diff --git a/Assets/Battle/BattleParticipant.cs b/Assets/Battle/BattleParticipant.cs index 4196f73..83439b7 100644 --- a/Assets/Battle/BattleParticipant.cs +++ b/Assets/Battle/BattleParticipant.cs @@ -16,7 +16,7 @@ public class BattleParticipant return this.hp; } - public int geMaxHP() { + public int getMaxHP() { return this.maxHP; } diff --git a/Assets/Battle/BattleScene.unity b/Assets/Battle/BattleScene.unity index b992d1b..a5eea16 100644 --- a/Assets/Battle/BattleScene.unity +++ b/Assets/Battle/BattleScene.unity @@ -385,7 +385,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -490, y: -245.5} + m_AnchoredPosition: {x: -490, y: -279} m_SizeDelta: {x: 160, y: 30} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &527589755 @@ -414,13 +414,13 @@ MonoBehaviour: m_BestFit: 0 m_MinSize: 10 m_MaxSize: 40 - m_Alignment: 0 + m_Alignment: 3 m_AlignByGeometry: 0 m_RichText: 1 m_HorizontalOverflow: 0 m_VerticalOverflow: 0 m_LineSpacing: 1 - m_Text: New Text + m_Text: 'Energy left: 3/3' --- !u!222 &527589756 CanvasRenderer: m_ObjectHideFlags: 0 diff --git a/Assets/Battle/HeroInfoUI.cs b/Assets/Battle/HeroInfoUI.cs index 110b2b5..2d0e7f4 100644 --- a/Assets/Battle/HeroInfoUI.cs +++ b/Assets/Battle/HeroInfoUI.cs @@ -5,14 +5,19 @@ using UnityEngine.UI; public class HeroInfoUI : MonoBehaviour { - public GameObject target; - public BattleParticipant battleParticipant; + protected GameObject target; + protected BattleParticipant battleParticipant; public Text nameText; public Image healthBarBgImage; public Image healthBarFgImage; private Camera mainCamera; + public void Init(GameObject sprite, BattleParticipant battleParticipant) { + this.target = sprite; + this.battleParticipant = battleParticipant; + } + // Start is called before the first frame update void Start() { @@ -25,5 +30,9 @@ public class HeroInfoUI : MonoBehaviour { Vector3 targetPos = this.mainCamera.WorldToScreenPoint(target.transform.position); transform.position = targetPos; + + int hp = battleParticipant.getHP(); + int maxHP = battleParticipant.getMaxHP(); + healthBarFgImage.fillAmount = ((float) hp) / maxHP; } }