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.

37 lines
890 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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.");
}
}
}