详细内容可以参考资料中查阅。
using UnityEngine;
using UnityEngine.Assertions;
public class AssertionExampleClass : MonoBehaviour
{
public int health;
public GameObject go;
void Update()
{
// You expect the health never to be equal to zero
Assert.AreNotEqual(0, health);//当变量health的值不为0的时候,可以正常运行,否则报错
// The referenced GameObject should be always (in every frame) be active
Assert.IsTrue(go.activeInHierarchy);//当go.activeInHierarchy实体的属性activeInHierarchy为true真的时候,可以正常运行,否则就会报错。
}
}
Assert断言的使用,可以很好的解决NullReferenceException问题
参考资料:
1.Assert
2.