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

        今天我们完成任务系统的一些项目,在B站视频中,有些代码有错误,(代码似乎没有错误)可能是没有加Box collider在我们的版本中无法实现功能,在我们的脚本中已经修改,比如UICamera.hoveredObject == null ,我们将它修改为!UI Camera.isOverUI ,并为Quest增加了一个Box collider。

public class BarNPC : MonoBehaviour {

		public TweenPosition questTween;
		public UILabel desLable;

		public bool isInTask = false;//表示是否在任务中
		public int killCount = 0;
		public GameObject acceptBtnGo;
		public GameObject OkBtnGo;
		public GameObject CancelBtnGo;

		private PlayerStatus status;

		private void Start ()
		{
				status = GameObject.FindGameObjectWithTag (Tags.player).GetComponent<PlayerStatus>();
		}

		void OnMouseOver ()
		{
				if (Input.GetMouseButtonDown (0)) {
						if (isInTask) {
								ShowTaskPrograss ();
						} else {
								ShowTaskDes ();
						}
						ShowQuest ();
				}
		}
		void ShowQuest ()
		{
				questTween.gameObject.SetActive (true);
				questTween.PlayForward();//播放动画
		}
		void HideQuest ()
		{
				questTween.PlayReverse ();//隐藏动画
		}

		void ShowTaskDes ()
		{
				desLable.text = "Task:\nKill Ten Wolves\n\nReward:\n1000Gold";
				OkBtnGo.SetActive (false);
				acceptBtnGo.SetActive (true);
				CancelBtnGo.SetActive (true);
		}
		void ShowTaskPrograss ()
		{
				desLable.text = "Task:\nYou've Killed  " + killCount + "\\Ten  Wolves\n\nReward:\n1000Gold";
				OkBtnGo.SetActive (true);
				acceptBtnGo.SetActive (false);
				CancelBtnGo.SetActive (false);
		}
		//任务系统对话框上的按钮点击时间的处理
		public void OnCloseButtonClick ()
		{
				HideQuest ();
		}
		public void OnAcceptButtonClick ()
		{
				ShowTaskPrograss ();
				isInTask = true;//表示在任务中
		}
		public void OnCancelButtonClick ()
		{
				HideQuest ();
		}
		public void OnOKButtonClick ()
		{//完成任务
				if (killCount >= 10) {

						status.GetCoin (1000);
						killCount = 0;
						ShowTaskDes ();
				}//未完成任务
				else {
						HideQuest ();
				}
		}
}
public void GetCoin(int count)
		{
				coin += count;
		}

		void Update ()
		{
				
				if (Input.GetMouseButtonDown (0) && !UICamera.isOverUI)//视频中代码会导致人物无法移动,修改为UI是否点击,并添加BoxCollider;

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

李曼竹

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

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

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

打赏作者

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

抵扣说明:

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

余额充值