# Cloud Code JavaScript 파일

> Manage your Cloud Code scripts from the Unity Editor using script files and the Deployment package.

Cloud Code JavaScript 파일을 사용하여 Unity 에디터에서 스크립트를 관리합니다. [Deployment 패키지](https://docs.unity3d.com/Packages/com.unity.services.deployment@latest)를 사용하여 Unity Dashboard에 스크립트를 배포할 수 있습니다.

## 필수 조건##prerequisites

Cloud Code 스크립트를 사용하려면 [Deployment 패키지](https://docs.unity3d.com/Packages/com.unity.services.deployment@latest)(`com.unity.services.deployment`)를 설치해야 합니다.

## Cloud Code 스크립트 파일을 만듭니다##create-cloud-code-script-files

Cloud Code 스크립트 파일을 만들려면 다음 내용을 따릅니다.

1. Unity 에디터에서 프로젝트 창을 오른쪽 클릭하고 **Create** > **Services** > **Cloud Code Js Script**를 선택합니다.

## 파일 포맷##file-format

파일 포맷은 .js 표준을 따릅니다.

> **Warning:**
>
> **중요**: 파라미터를 설정하기 전에 `module.exports` 프로퍼티를 할당해야 합니다.

### 예시##example

```javascript
/*
 *  -------- Example Cloud Code Script --------
 *
 *  Roll a 6-sided dice and get back the result
 *
 * --------------------------------------------
 * Additional imports are limited to:
 *  - lodash-4.17
 *  - axios-0.21
 *  - @unity-services/cloud-save-1.0
 *  - @unity-services/economy-2.0
 *  - @unity-services/remote-config-1.0
 */
 // Include the lodash module for convenient functions such as "random"
const _ = require("lodash-4.17");

const NUMBER_OF_SIDES = 6;

/*
 * CommonJS wrapper for the script. It receives a single argument, which can be destructured into:
 *  - params: Object containing the parameters provided to the script, accessible as object properties
 *  - context: Object containing the projectId, environmentId, environmentName, playerId and accessToken properties.
 *  - logger: Logging client for the script. Provides debug(), info(), warning() and error() log levels.
 */
module.exports = async ({ params, context, logger }) => {
  // Log an info message with the parameters provided to the script and the invocation context
  logger.info("Script parameters: " + JSON.stringify(params));
  logger.info("Authenticated within the following context: " + JSON.stringify(context));

  const roll = rollDice(NUMBER_OF_SIDES);

  if (roll > NUMBER_OF_SIDES) {
    // Log an error message with information about the exception
    logger.error("The roll is greater than the number of sides: " + roll);
    // Return an error back to the client
    throw Error("Unable to roll dice!");
  }

  // Return the JSON result to the client
  return {
    sides: NUMBER_OF_SIDES,
    roll: roll,
  };
};

// Functions can exist outside of the script wrapper
function rollDice(sides) {
  return _.random(1, sides);
}
```

저작(authoring) 옵션에 관한 자세한 내용은 [에디터에서 스크립트 작성](./write-scripts/unity-editor.md)을 참고하십시오.

## 파일 배포##deploy-files

Cloud Code 스크립트 파일을 생성하면 선택한 환경에 파일을 배포할 수 있습니다.

파일을 배포하려면 다음 내용을 따릅니다.

1. Unity 에디터에서 **Services** > **Deployment**를 선택합니다. Unity 버전이 2022 미만인 경우 **Window** > **Deployment**를 선택합니다. Deployment 창에 로컬 Cloud Code 스크립트 파일이 표시됩니다.
2. 선택된 Cloud Code 스크립트 파일을 선택하고 **Deploy Selected**를 선택합니다.

이제 [Unity Dashboard](./write-scripts/unity-dashboard.md)에서 Cloud Code 스크립트를 편집할 수 있습니다.

Deployment 창에서의 작업에 관한 자세한 내용은 [Deployment 패키지](https://docs.unity3d.com/Packages/com.unity.services.deployment@latest)를 참고하십시오.
