# 創建演員類

演員在你的專案代碼中是以類/class的形式實現的。

### 創建新的演員類

演員類在你的代碼中定義為 `.ts` 文件。慣例是將這些文件放在 `src/actors`。文件夾中。在下面的代碼中，我們有一個演員的基本起點。

```typescript

// src/actors/example-actor.ts
import { Actor, BaseActor } from "@hology/core/gameplay";

@Actor()
class ExampleActor extends BaseActor {

  onInit() {
    
  }
  
  onBeginPlay() {
  
  }
  
  onEndPlay() {
  
  }
  
  onUpdate(deltaTime: number) {
    
  }
  
}

export default ExampleActor 

```

如果你只打算通過遊戲生成演員，這就是你所需要的全部內容。

#### 在 Hology 編輯器中使演員可用

除了定義你的類，你還需要導出它。這是在 `index.ts` 文件中完成的。如果不這樣做，編輯器將無法找到你的演員類。

```typescript

// src/actors/index.ts
import ExampleActor from "./example-actor";

export default {
  ExampleActor,
  // add other actors here
}

```

### 從編輯器創建演員類

創建演員起始代碼的一個更簡單的方法是通過編輯器來完成。它將為你生成具有給定演員類名稱的代碼。在資產瀏覽器中點擊"添加新建/Add new"按鈕，然後選擇"演員類/Actor class"。

<img src="/files/AdvfpUfJ2Q50bUOPWy9T" alt="Create actor classes from editor" data-size="original">

### 熱重載/Hot reloading

編輯器將監控你的代碼，以找到任何可以在你的場景中實例化為演員實例的新演員類。此外，如果演員代碼發生變化，你場景中的演員將被刷新以反映任何視覺上的變化。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hology.app/zh-tw/gameplay/yan-yuan-actors/chuang-jian-yan-yuan-lei.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
