# Unity 特性

> Use Unity-specific C# attributes to define special behavior for your code.

C# 中的[特性 (Attribute)](https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/reflection-and-attributes/) 是可以放在类、属性或方法声明上方来指示特殊行为的元数据标记。

.NET 库中定义了许多特性，Unity 也提供了大量特定于 Unity 的自定义特性。例如，可以将 `HideInInspector` 特性添加到属性声明上方，从而防止检视面板 (Inspector) 显示该属性（即使是公共属性）。特性在声明上方的方括号中指定，形式如下：

```lang-csharp
[HideInInspector]
public float strength;
```

有关 `UnityEngine` 特性的完整列表，请参阅脚本 API 参考中的 **UnityEngine > 特性 (Attributes)** 下方列表，该列表以 [AddComponentMenu](/engine/6000.0/script-reference/unity-engine/add-component-menu.md) 开头。

有关 `UnityEditor` 属性的完整列表，请参阅脚本 API 参考中的 **UnityEditor > 特性 (Attributes)** 下方列表，该列表以 [AssetPostprocessorStaticVariableIgnoreAttribute](/engine/6000.0/script-reference/unity-editor/asset-postprocessor-static-variable-ignore-attribute.md) 开头。

\*\*注意：\*\*请勿使用 .NET [ThreadStatic](http://msdn.microsoft.com/en-us/library/system.threadstaticattribute.aspx) 特性，因为如果将 .NET ThreadStatic 特性添加到 Unity 脚本中，则会导致崩溃。

## 其他资源

* [Unity Learn：特性](https://learn.unity.com/tutorial/attributes#)
* [检查脚本](/engine/6000.0/manual/scripting/get-started/inspecting-scripts.md)
* [脚本序列化规则](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-serialization/rules.md)
