【发布时间】:2022-12-05 18:41:05
【问题描述】:
我正在尝试从 Unity 中的图像获取精灵,但我遇到了一个问题。我正在使用这段代码:
void Start () {
Sprite sprite = this.gameObject.GetComponent<Image> ().sprite;
if (sprite == null) {
Debug.Log ("NULL");
} else {
Debug.Log ("NOT NULL");
}
}
如果精灵是空的,它不会识别为“空”。为什么?以及如何解决?
【问题讨论】: