You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.6 KiB
60 lines
1.6 KiB
using UnityEngine; |
|
using System.Collections; |
|
using UnityEngine.UI; |
|
using System; |
|
|
|
public class EquipPlusOrReduce : MonoBehaviour { |
|
public GameObject NumLable; |
|
string buttonName; |
|
public int equipNum; |
|
GameObject confirmBtn; |
|
GameObject reduceButton; |
|
GameObject plusButton; |
|
// Use this for initialization |
|
void Start () { |
|
buttonName = this.name; |
|
confirmBtn = this.transform.parent.Find("ConfirmButton").gameObject; |
|
reduceButton = this.transform.parent.Find("ReduceButton").gameObject; |
|
plusButton = this.transform.parent.Find("PlusButton").gameObject; |
|
|
|
this.GetComponent<Button>().onClick.AddListener(OnClick); |
|
} |
|
|
|
private void OnClick() |
|
{ |
|
int oldEquipNum = confirmBtn.GetComponent<ConfirmSelectEquipNum>().equipNum; |
|
if (buttonName == "ReduceButton") |
|
{ |
|
if (equipNum > 0) |
|
{ |
|
equipNum--; |
|
if (oldEquipNum > 0) |
|
oldEquipNum--; |
|
} |
|
} |
|
|
|
if (buttonName == "PlusButton") |
|
{ |
|
equipNum++; |
|
|
|
oldEquipNum++; |
|
} |
|
|
|
NumLable.GetComponent<InputField>().text = equipNum.ToString(); |
|
|
|
reduceButton.GetComponent<EquipPlusOrReduce>().equipNum = equipNum; |
|
plusButton.GetComponent<EquipPlusOrReduce>().equipNum = equipNum; |
|
|
|
confirmBtn.GetComponent<ConfirmSelectEquipNum>().equipNum = oldEquipNum; |
|
} |
|
|
|
// Update is called once per frame |
|
void Update () { |
|
|
|
} |
|
|
|
void OnDestroy() |
|
{ |
|
this.GetComponent<Button>().onClick.RemoveListener(OnClick); |
|
} |
|
}
|
|
|