# 世界

World/世界服務用於需要與世界互動的代碼,如生成角色、查找角色或控制定向光。

通過在您的服務、角色和組件類中注入World來訪問世界。

```typescript

@Service()
class Game extends GameInstance {
    private world = inject(World)
    
    onStart() {
        
    }
    
}
```

## 定向光/Directional Light

預設情況下,每個場景都有產生陰影的定向光。您可能想要訪問它以在運行時更新方向或強度。

```typescript
@Service()
class Game extends GameInstance {
    private world = inject(World)
    
    onStart() {
        this.world.directionalLight.intensity = 0.2 
        this.world.directionalLight.direction.applyAxisAngle(new THREE.Vector3(0,0,1), Math.PI / 2)

    }
    
}
```

&#x20;定向光暴露以下:

* **direction**: Vector3 - 可以更新方向向量以改變光的方向。這可用於模擬太陽。
* **intensity**: number - 光的亮度。
* **position:** Vector3 - 定向光實例的位置。這不能被改變;相反,請改變方向。


---

# 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/shi-jie.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.
