1
This commit is contained in:
91
unity/Assets/Script/UI/CharacterHp.cs
Normal file
91
unity/Assets/Script/UI/CharacterHp.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CharacterHp : MonoBehaviour
|
||||
{
|
||||
public GameObject EndUI;
|
||||
|
||||
//UI
|
||||
public Image headImage;
|
||||
private float maxHp;
|
||||
public Slider hpBar;
|
||||
public Text bossName;
|
||||
public Text hpText;
|
||||
public Text atk;
|
||||
|
||||
private Animator _animator;
|
||||
private BossAI bossAI;
|
||||
private CharacterCombat charComba;
|
||||
private void Awake()
|
||||
{
|
||||
hpBar.value = 1;
|
||||
}
|
||||
public void Init(BossAI ai)
|
||||
{
|
||||
_animator = ai._animator;
|
||||
headImage.overrideSprite = ai._info.bossHead;
|
||||
maxHp = ai.maxHp;
|
||||
hpText.text = maxHp + "/" + maxHp;
|
||||
|
||||
bossAI = ai;
|
||||
bossName.text = ai._info.bossName;
|
||||
ai.OnHit += OnUpdate;
|
||||
}
|
||||
public void Init(CharacterCombat ch)
|
||||
{
|
||||
_animator = ch._animator;
|
||||
maxHp = ch.maxHp;
|
||||
hpText.text = ch.currentHp + "/" + maxHp;
|
||||
charComba = ch;
|
||||
atk.text = ch.attack.ToString();
|
||||
bossName.text = PlayerInfo.Instance.info.playerName;
|
||||
ch.OnHit += OnUpdate;
|
||||
}
|
||||
|
||||
private void OnUpdate(float hp)
|
||||
{
|
||||
if(bossAI==null)
|
||||
{
|
||||
maxHp = charComba.maxHp;
|
||||
atk.text = charComba.attack.ToString();
|
||||
}
|
||||
hpBar.value = hp/maxHp;
|
||||
hpText.text = hp + "/" + maxHp;
|
||||
if (hp<=0)
|
||||
{
|
||||
_animator.Play("die");
|
||||
hpText.text = "0/" + maxHp;
|
||||
if (charComba==null)//¹ÖÎչʾÖÕ½áUI
|
||||
{
|
||||
EndUI.SetActive(true);
|
||||
StartCoroutine(StartTimer(1f));
|
||||
}
|
||||
else
|
||||
{
|
||||
UIManager.Instance.Show<UIGameOver>();
|
||||
}
|
||||
}
|
||||
}
|
||||
IEnumerator StartTimer(float t)
|
||||
{
|
||||
yield return new WaitForSeconds(t);
|
||||
|
||||
EndUI.SetActive(false);
|
||||
yield return new WaitForSeconds(t);
|
||||
|
||||
//½±Àø
|
||||
UIManager.Instance.Show<UILottery>();
|
||||
PlayerInfo.Instance.BagMgr.AddItem(1, 2);
|
||||
PlayerInfo.Instance.BagMgr.AddItem(0, 2);
|
||||
PlayerInfo.Instance.info.exp += 2000;
|
||||
PlayerInfo.Instance.LevelUp();
|
||||
PlayerInfo.Instance.OnUpdateLevel?.Invoke();
|
||||
//
|
||||
|
||||
this.gameObject.SetActive(false);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user