用Unity/C# Assert解决NullPointerException的一种方法
发布时间
阅读量:
阅读量
具体信息可参考相关文献资料进行查询。
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真的时候,可以正常运行,否则就会报错。
全部评论 (0)
还没有任何评论哟~
