using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CardCounter : MonoBehaviour { public Text counterText; private int counter = 0; public bool SetCounter(int _value) { counter += _value; OnCounterChange(); if (counter == 0) { Destroy(gameObject); return false; } return true; } private void OnCounterChange()//给卡牌数量文本字段赋值 { //测试是否拿到counter数据,这里成功 //Debug.Log("counter:"+counter.ToString()); if (counterText != null) // 添加空值检查 { counterText.text = counter.ToString(); } else { Debug.LogError("counterText is null, please assign a Text component in the inspector."); } } }