基类:
using UnityEngine; using System.Collections; public class CommonNPC : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnMouseEnter() { MouseCursor._instance.SetCursorDialog(); } void OnMouseExit() { MouseCursor._instance.SetCursorHand(); } }
子类:
using UnityEngine; using System.Collections; public class NPCTask : CommonNPC { public TweenPosition TweenPos; public GameObject ConfirmButton; public GameObject CancelButton; public GameObject FinishButton; public UILabel Label; public int KilledAnimals; private bool IsTasking; // Use this for initialization void Start () { IsTasking = false; KilledAnimals = 0; FinishButton.SetActive(false); } void OnMouseOver() { if (Input.GetMouseButtonDown(0)) { TweenPos.gameObject.SetActive(true); TweenPos.PlayForward(); if(IsTasking==false)//接收任务 { Label.text = "任务:杀死10个动物\n奖励:1000金币" ; FinishButton.SetActive(false); ConfirmButton.SetActive(true); CancelButton.SetActive(true); } else//提交任务 { Label.text = "已经杀死" + KilledAnimals + "个动物"; FinishButton.SetActive(false); ConfirmButton.SetActive(true); CancelButton.SetActive(true); } } } public void OnClickConfirm()//接收任务 { Label.text = "已经杀死" + KilledAnimals + "个动物"; FinishButton.SetActive(false); ConfirmButton.SetActive(true); CancelButton.SetActive(true); IsTasking = true; } public void OnClickCancel() { TweenPos.PlayReverse(); } public void OnClickFinish()//提交任务 { if(KilledAnimals>=10) { // } } // Update is called once per frame void Update () { } }
时间: 2024-10-18 17:17:10