# 测试条件编译

> Code example and steps to test your conditionally compiled code.

以下示例展示了如何测试条件编译代码。它还会根据为目标构建选择的平台打印一条消息。

## 代码示例##sample-code

```lang-csharp

using UnityEngine;
using System.Collections;
public class PlatformDefines : MonoBehaviour {
void Start () {

  #if UNITY_EDITOR
    Debug.Log("Unity Editor");
  #endif

  #if UNITY_IOS
    Debug.Log("Unity iOS");
  #endif

  #if UNITY_STANDALONE_OSX
      Debug.Log("Standalone OSX");
  #endif

  #if UNITY_STANDALONE_WIN
    Debug.Log("Standalone Windows");
  #endif

}			 
} 
```

## 测试说明##test-instructions

1. 打开**构建配置文件 (Build Profiles)** 窗口（菜单：**文件 (File)** > **构建配置文件 (Build Profiles)**）。
2. 检查要用来测试代码的平台是否为当前激活 (Active) 的平台配置文件。如否，请选择首选平台，然后单击**切换配置文件 (Switch Profile)**。
3. 创建[脚本](/engine/6000.0/manual/scripting/get-started/creating-scripts.md)并复制和粘贴以下[示例代码](#Sample)。
4. 在[游戏 (Game) 视图](/engine/6000.0/manual/unity-editor/using-the-editor/game-view.md)中，单击播放 (Play) 按钮，进入播放 (Play) 模式。检查与 Unity 控制台中所选平台相关的消息，确认代码是否正常工作。例如，如果选择 iOS，则消息 `Unity Editor` 和 `Unity iOS` 将显示在控制台中。

## 其他资源##additional-resources

* [Unity 脚本符号参考](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/conditional-compilation/symbol-reference.md)
* [自定义脚本符号](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/conditional-compilation/custom-scripting-symbols.md)
