今天完成了角色的状态栏和药店的购买功能,与前面较为相同,相对简单
public bool GetPoint(int point = 1)
{
if(point_remain >= point) {
point_remain -= point;
return true;
}
return false;
}
public class ShopDrugNPC :NPC{
private AudioSource source;
void Awake ()
{
source = this.GetComponent<AudioSource> ();
}
public void OnMouseOver ()
{//当鼠标在这个游戏物体之上
if (Input.GetMouseButtonDown (0)) {//弹出药店列表
source.Play ();
ShopDrug._instance.TransformState ();
}
}
}
public class ShopDrug : MonoBehaviour {
public static ShopDrug _instance;
private TweenPosition tween;
private bool isShow = false;
private GameObject numberDialog;
private UIInput numberInput;
private int Buy_id = 0;
void Awake ()
{
_instance = this;
tween = this.GetComponent<TweenPosition> ();
numberDialog = this.transform.Find ("NumberDialog").gameObject;
numberInput = transform.Find ("NumberDialog/NumberInput").GetComponent<UIInput> ();
numberDialog.SetActive (false);
}
public void TransformState ()
{
if(isShow == false) {
tween.PlayForward ();isShow = true;
} else {
tween.PlayReverse ();isShow = false;
}
}
public void OnCloseButtonClick ()
{
TransformState ();
}
public void OnBuyId1001 ()
{
Buy (1001);
}
public void OnBuyId1002 ()
{
Buy (1002);
}
public void OnBuyId1003 ()
{
Buy (1003);
}
void Buy(int id)
{
ShowNumberDialog ();
Buy_id = id;
}
public void OnOKButtonClick ()
{
int count = int.Parse (numberInput.value);
ObjectInfo info = ObjectsInfo._instance.GetObjectInfoById (Buy_id);
int price = info.price_buy;
int price_totol = price * count;
bool success = Inventory._instance.GetCoin (price_totol);
if (success) {//购买成功
if(count > 0) {
Inventory._instance.GetId (Buy_id, count);
}
}
numberDialog.SetActive (false);
}
void ShowNumberDialog ()
{
numberDialog.SetActive (true);
numberInput.value = "0";
}
}