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.
49 lines
992 B
49 lines
992 B
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
public class PlusMinusCtrl : MonoBehaviour |
|
{ |
|
|
|
public InputField NumberInput; |
|
public Button PlusBtn; |
|
public Button MinusBtn; |
|
private int number = 0; |
|
|
|
public int Number |
|
{ |
|
get |
|
{ |
|
return number; |
|
} |
|
|
|
set |
|
{ |
|
this.number = value; |
|
NumberInput.text = number.ToString(); |
|
} |
|
} |
|
|
|
// Use this for initialization |
|
void Start() |
|
{ |
|
PlusBtn.onClick.AddListener(Plus); |
|
NumberInput.onEndEdit.AddListener(InputNumber); |
|
MinusBtn.onClick.AddListener(Minus); |
|
} |
|
void Plus() |
|
{ |
|
Number++; |
|
// NumberInput.text = Number.ToString(); |
|
} |
|
void Minus() |
|
{ |
|
Number = --Number <= 1 ? 1 : Number; |
|
// NumberInput.text = Number.ToString(); |
|
} |
|
void InputNumber(string value) |
|
{ |
|
Number = int.Parse(value); |
|
} |
|
}
|
|
|