WXMC/.svn/pristine/13/138788341f3110504132c014106ece6b86c57f8c.svn-base

66 lines
2.0 KiB
Plaintext
Raw Permalink Normal View History

2024-12-04 16:18:46 +08:00
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LifePopup : MonoBehaviour
{
public Text lifeRemain;
public Text recoveryCost;
public GameObject recoveryButton;
int cost;
// Use this for initialization
void Start ()
{
if (Configure.instance.life < Configure.instance.maxLife)
{
lifeRemain.text = "Life: " + Configure.instance.life.ToString() + "/" + Configure.instance.maxLife.ToString();
cost = Configure.instance.recoveryCostPerLife * (Configure.instance.maxLife - Configure.instance.life);
recoveryCost.text = cost.ToString();;
}
else
{
lifeRemain.text = "Life: " + Configure.instance.maxLife.ToString() + "/" + Configure.instance.maxLife.ToString();
recoveryButton.SetActive(false);
recoveryCost.gameObject.transform.parent.gameObject.SetActive(false);
}
}
public void ButtonClickAudio()
{
AudioManager.instance.ButtonClickAudio();
}
public void RecoveryButtonClick()
{
// check coin
if (GameData.instance.playerCoin < cost)
{
// open shop popup
GameObject.Find("MapScene").GetComponent<MapScene>().CoinButtonClick();
}
else
{
// reduce coin and refill life
GameData.instance.SavePlayerCoin(GameData.instance.GetPlayerCoin() - cost);
// play add coin sound
AudioManager.instance.CoinPayAudio();
// update text label
GameObject.Find("MapScene").GetComponent<MapScene>().UpdateCoinAmountLabel();
// update life text
GameObject.Find("LifeBar").GetComponent<Life>().AddLife(Configure.instance.maxLife);
// update life pupup text
lifeRemain.text = "Life: " + Configure.instance.maxLife.ToString() + "/" + Configure.instance.maxLife.ToString();
recoveryButton.SetActive(false);
recoveryCost.gameObject.transform.parent.gameObject.SetActive(false);
}
}
}