Unity之黑暗之光按教程学习第八天

       今天完成了角色的状态栏和药店的购买功能,与前面较为相同,相对简单


		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";
		}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李曼竹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值