mycj_demo/mycj/Assets/Script/PlayerInfo.cs

64 lines
1.4 KiB
C#
Raw Normal View History

2024-12-02 09:37:47 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class PlayerInfo : MonoBehaviour
{
public static PlayerInfo instance;
[Header("<22><>ʾgold<6C><64><EFBFBD>ı<EFBFBD>")]
public Text goldText;
[Header("<22><>ʾhp<68><70><EFBFBD>ı<EFBFBD>")]
public Text hpText;
[Header("<22><><EFBFBD><EFBFBD>PlayerHp<48><70>Ĭ<EFBFBD><C4AC>Ϊ5")]
public float maxPlayerHp=5;
private float playerHp=0;
[Header("PlayerGold<6C><64>Ĭ<EFBFBD><C4AC>Ϊ0")]
public float playerGold;
public event Action OnGoldReachedThreshold;
// Start is called before the first frame
private void Awake()
{
instance = this;
}
void Start()
{
ChangeHp(maxPlayerHp);
ChangeGold(0);
}
// Update is called once per frame
void Update()
{
}
public void ChangeHp(float number)
{
if ((this.playerHp +number)<=0)
{
Penal.instance.GameOver();
}
this.playerHp += number;
UpdateShow();
}
public void ChangeGold(float number)
{
this.playerGold += number;
if (this.playerGold>=10)
{
OnGoldReachedThreshold?.Invoke();
}
UpdateShow();
}
void UpdateShow()
{
goldText.text = "<22><><EFBFBD>ң<EFBFBD>" + playerGold.ToString();
hpText.text = "<22><><EFBFBD><EFBFBD>Hp<48><70>" + playerHp.ToString() + "/" + maxPlayerHp.ToString();
}
}