123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using static UnityEditor.Progress;
- public class Adjust_values : MonoBehaviour
- {
- public List<Button> JiabtnList = new List<Button>();
- public List<Button> JianbtnList = new List<Button>();
- public List<Text> valueTextList = new List<Text>();
- public List<int> values = new List<int>();
- public Text valueText;
- public Button randomBtn;
- public Button startNewLifeBtn;
- void Start()
- {
- for (int j = 0; j < 4; j++)
- {
- values.Add(0);
- }
- foreach (var item in valueTextList)
- {
- item.text = 0.ToString();
- }
- for (int i = 0; i < JiabtnList.Count; i++)
- {
- int index = i;
- JiabtnList[i].onClick.AddListener(() =>
- {
- int sum = 0;
- for (int j = 0; j < values.Count; j++)
- {
- sum += values[j];
- }
- if (sum < 20)
- {
- values[index]++;
- valueTextList[index].text = values[index].ToString();
- }
- int tempSum = 0;
- for (int j = 0; j < values.Count; j++)
- {
- tempSum += values[j];
- }
- valueText.text = (20 - tempSum).ToString();
- });
- }
- for (int i = 0; i < JianbtnList.Count; i++)
- {
- int index = i;
- JianbtnList[i].onClick.AddListener(() =>
- {
- if (values[index] > 0)
- {
- values[index]--;
- valueTextList[index].text = values[index].ToString();
- }
- int sum = 0;
- foreach (var item in values)
- {
- sum += item;
- }
- valueText.text = (20 - sum).ToString();
- });
- }
- randomBtn.onClick.AddListener(() =>
- {
- for (int i = 0; i < 4; i++)
- {
- values[i] = 0;
- }
- for (int i = 0; i < 20; i++)
- {
- int index = Random.Range(0, values.Count);
- values[index]++;
- valueTextList[index].text = values[index].ToString();
- }
- valueText.text = 0.ToString();
- });
- startNewLifeBtn.onClick.AddListener(() =>
- {
- int sum = 0;
- for (int j = 0; j < values.Count; j++)
- {
- sum += values[j];
- }
- if (sum != 20)
- {
- Debug.Log("请分配属性到20点");
- }
- else
- {
- PlayerData.intance.CHR = values[0];
- PlayerData.intance.INT = values[1];
- PlayerData.intance.STR = values[2];
- PlayerData.intance.MNY = values[3];
- Debug.Log("祝你生活愉快");
- }
- });
- }
- void Update()
- {
- }
- }
|