Version: 2022.1

Assert.AreNotApproximatelyEqual

切换到手册
public static void AreNotApproximatelyEqual (float expected, float actual);
public static void AreNotApproximatelyEqual (float expected, float actual, string message);
public static void AreNotApproximatelyEqual (float expected, float actual, float tolerance);
public static void AreNotApproximatelyEqual (float expected, float actual, float tolerance, string message);

参数

tolerance 近似公差。
expected 假设的 Assert 值。
actual 确切的 Assert 的值。
message 用于描述 Assert 的字符串。

描述

断言值近似不相等。

使用绝对错误检查执行近似相等性检查(|a-b| < 公差)。默认公差为 0.00001f。

using UnityEngine;
using UnityEngine.Assertions;

public class AssertionExampleClass : MonoBehaviour { Rigidbody rb;

void Update() { // Make sure the rigidbody never stops. // AreNotApproximatelyEqual should be used for comparing floating point variables. // Unless specified, default error tolerance will be used. Assert.AreNotApproximatelyEqual(0.0f, rb.velocity.magnitude); } }