95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class Buildings : MonoBehaviour
|
|||
|
{
|
|||
|
// Start is called before the first frame update
|
|||
|
public int Level;
|
|||
|
public int MaxLevel;
|
|||
|
public List<int> upgradeNeeds_Wood;
|
|||
|
public List<int> upgradeNeeds_Stone;
|
|||
|
|
|||
|
public Canvas information_Panel;
|
|||
|
void Start()
|
|||
|
{
|
|||
|
Level = 1;
|
|||
|
//StartCoroutine(Second());
|
|||
|
InvokeRepeating("AddResources_Auto", 1, 1);
|
|||
|
information_Panel.transform.Find("NextUpgradeNeeds").GetComponent<Text>().text = "<22>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n" + "ľͷ" + upgradeNeeds_Wood[Level] + "\n" + "ʯͷ" + upgradeNeeds_Stone[Level];
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
void Update()
|
|||
|
{
|
|||
|
if (Level < MaxLevel)
|
|||
|
{
|
|||
|
if (Check_Upgrade())
|
|||
|
{
|
|||
|
information_Panel.transform.Find("Upgrade").GetComponent<Button>().interactable = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
information_Panel.transform.Find("Upgrade").GetComponent<Button>().interactable = false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnMouseDown()
|
|||
|
{
|
|||
|
AddResources_Click();
|
|||
|
}
|
|||
|
|
|||
|
public bool Check_Upgrade()
|
|||
|
{
|
|||
|
if (Resources.Instance.wood >= upgradeNeeds_Wood[Level] && Resources.Instance.stone >= upgradeNeeds_Stone[Level])
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public void Upgrade()
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
string Animation_Name = "Upgrade_" + Level;
|
|||
|
GetComponent<Animator>().Play(Animation_Name);
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
Resources.Instance.wood -= upgradeNeeds_Wood[Level];
|
|||
|
Resources.Instance.stone -= upgradeNeeds_Stone[Level];
|
|||
|
Level += 1;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵUI<55><49>ʾ
|
|||
|
information_Panel.transform.Find("Level").GetComponent<Text>().text = "<22><>ǰ<EFBFBD>ȼ<EFBFBD>Ϊ:"+Level;
|
|||
|
information_Panel.transform.Find("Production_Click").GetComponent<Text>().text = "ÿ<>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" + Level*5;
|
|||
|
information_Panel.transform.Find("Production_Auto").GetComponent<Text>().text = "ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" + (Level-1);
|
|||
|
if (Level < MaxLevel)
|
|||
|
{
|
|||
|
information_Panel.transform.Find("NextUpgradeNeeds").GetComponent<Text>().text = "<22>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n" + "ľͷ" + upgradeNeeds_Wood[Level] + "\n" + "ʯͷ" + upgradeNeeds_Stone[Level];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
information_Panel.transform.Find("NextUpgradeNeeds").GetComponent<Text>().text = "<22>Ѵﵽ<D1B4><EFB5BD><EFBFBD>ߵȼ<DFB5>";
|
|||
|
}
|
|||
|
|
|||
|
information_Panel.transform.Find("Upgrade").GetComponent<Button>().interactable = false;
|
|||
|
}
|
|||
|
//-----------------------------------------------------------------------------------------------------
|
|||
|
|
|||
|
public virtual void AddResources_Click()
|
|||
|
{
|
|||
|
Debug.Log("Click");
|
|||
|
}
|
|||
|
public virtual void AddResources_Auto()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
public IEnumerator Second()
|
|||
|
{
|
|||
|
AddResources_Auto();
|
|||
|
yield return new WaitForSeconds(1);
|
|||
|
}
|
|||
|
}
|