---
title: 使用常见的数学函数
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/zh-cn/engine/6000.0/manual/scripting/object-oriented-development/programming-math/class-mathf
latest_url: https://docs.unity.com/zh-cn/engine/7000.0/manual/scripting/object-oriented-development/programming-math/class-mathf.md
generated_at: 2026-11-16T10:08:06.493Z
locale: zh-cn
---

# 使用常见的数学函数

> 使用 Unity 的 Mathf 类可以Apply游戏Development中常见的三角函数、对数函数和Other数学函数。

Unity 的 Mathf 类提供了一Collection常见的数学函数，包括三角函数、对数函数以及游戏和应用Development中常见的Other函数。

Page面Overview了 Mathf 类及其在编写脚本When的常见用法。有关 Mathf 类每个成员的详尽参考，请参阅[ Mathf 脚本参考](/engine/6000.0/script-reference/unityengine/mathf.md)。

## 三角形##trigonometric

Unity 的所有三角函数都以**弧度**工作。

* [`Sin`](/engine/6000.0/script-reference/unityengine/mathf/sin.md)
* [`Cos`](/engine/6000.0/script-reference/unityengine/mathf/cos.md)
* [`Tan`](/engine/6000.0/script-reference/unityengine/mathf/tan.md)
* [`Asin`](/engine/6000.0/script-reference/unityengine/mathf/asin.md)
* [`Acos`](/engine/6000.0/script-reference/unityengine/mathf/acos.md)
* [`Atan`](/engine/6000.0/script-reference/unityengine/mathf/atan.md)
* [`Atan2`](/engine/6000.0/script-reference/unityengine/mathf/atan2.md)

[`PI`](/engine/6000.0/script-reference/unityengine/mathf/pi.md) 是常量，可以乘以 Static 值 [`Rad2Deg`](/engine/6000.0/script-reference/unityengine/mathf/rad2deg.md) 或 [`Deg2Rad`](/engine/6000.0/script-reference/unityengine/mathf/deg2rad.md) 在弧度和度之间转换。

## 幂和平方根##powers-and-square-roots

Unity 提供了所需的常见幂函数和平方根函数：

* [`Pow`](/engine/6000.0/script-reference/unityengine/mathf/pow.md)
* [`Sqrt`](/engine/6000.0/script-reference/unityengine/mathf/sqrt.md)
* [`Exp`](/engine/6000.0/script-reference/unityengine/mathf/exp.md)

以及一些有用的 2 的幂相关函数。在处理常见的Binary进制数据大小When，这些非常有用，这些大小通常受限或优化为 2 的幂值（例如纹理尺寸）：

* [`ClosestPowerOfTwo`](/engine/6000.0/script-reference/unityengine/mathf/closestpoweroftwo.md)
* [`NextPowerOfTwo`](/engine/6000.0/script-reference/unityengine/mathf/nextpoweroftwo.md)
* [`IsPowerOfTwo`](/engine/6000.0/script-reference/unityengine/mathf/ispoweroftwo.md)

## 插值##interpolation

Unity 的插值函数允许您计算位于两个给定点之间某个位置的值。每个函数的行为方式不同，适合不同情况。请参阅每个示例中的示例以了解更多信息：

* [`Lerp`](/engine/6000.0/script-reference/unityengine/mathf/lerp.md)
* [`LerpAngle`](/engine/6000.0/script-reference/unityengine/mathf/lerpangle.md)
* [`LerpUnclamped`](/engine/6000.0/script-reference/unityengine/mathf/lerpunclamped.md)
* [`InverseLerp`](/engine/6000.0/script-reference/unityengine/mathf/inverselerp.md)
* [`MoveTowards`](/engine/6000.0/script-reference/unityengine/mathf/movetowards.md)
* [`MoveTowardsAngle`](/engine/6000.0/script-reference/unityengine/mathf/movetowardsangle.md)
* [`SmoothDamp`](/engine/6000.0/script-reference/unityengine/mathf/smoothdamp.md)
* [`SmoothDampAngle`](/engine/6000.0/script-reference/unityengine/mathf/smoothdampangle.md)
* [`SmoothStep`](/engine/6000.0/script-reference/unityengine/mathf/smoothstep.md)

请注意，[矢量类](/engine/6000.0/manual/scripting/object-oriented-development/programming-math/vectors.md)和[`Quaternion`](/engine/6000.0/manual/working-with-gameobjects/gameobject-fundamentals/rotation-orientation/class-quaternion.md)类 All 都有自己的插值函数（例如四元数。Lerp），可用于在多个维度上插值位置、方向和旋转。

## 限制和重复值##limiting-and-repeating-values

这些Simple的 helper 函数通常在游戏中或应用程序中很有用，When需要将值Limit在一定范围内或在一定范围内重复时，这些函数可以Save您的时间。

* 4 和 5
* 4 和 5
* 4 和 5
* 4 和 5

## 对数##logarithmic

[`Log`](/engine/6000.0/script-reference/unityengine/mathf/log.md) 函数允许您计算指定数量的对数，可以是自然对数，也可以是指定底部的对数。此外，[`Log10`](/engine/6000.0/script-reference/unityengine/mathf/log10.md) 函数返回指定数量的底部 10 对数。

## Other 函数##other-functions

有关 Mathf 类中函数的完整列表，请参阅[ Mathf 脚本参考](/engine/6000.0/script-reference/unityengine/mathf.md)。
