---
title: 检查一个角色是否在地面上
slug: world-sdk-guide-ch/PgnGVbHuuVFu08w30EwnB
docTags: 
createdAt: 2024-09-02T08:34:13.135Z
---

在本指南中，我们将向您展示如何根据 `isGrounded` 函数检查本地玩家的 Zepeto 角色是否在地面上。

:::hint{type="info"}
**📘 CharacterController.isGrounded**
[https://docs.unity3d.com/ScriptReference/CharacterController-isGrounded.html](https://docs.unity3d.com/ScriptReference/CharacterController-isGrounded.html)
:::



### 步骤 1 : 编写脚本

- 将一个 GameObject 添加到场景中，并添加下面的 IsGrounded 示例脚本。

```typescript
import { ZepetoScriptBehaviour } from 'ZEPETO.Script'
import { ZepetoPlayers } from 'ZEPETO.Character.Controller';
import { Text } from 'UnityEngine.UI';
 
export default class IsGrounded extends ZepetoScriptBehaviour {
 
    public myText: Text;
 
    Update() {
        // 访问本地玩家的角色控制器
        const localCharacter = ZepetoPlayers.instance.LocalPlayer.zepetoPlayer.character.characterController;
 
        // 使用 isGrounded 检查角色控制器是否接触另一个碰撞体
        if (localCharacter.isGrounded) {
            this.myText.text = "角色在地面上";
        } else {
            this.myText.text = "角色不在地面上";
        }
    }
}
```



### 步骤 2 : 设置文本 UI

- 将 UI > 文本添加到场景中。
- 在层级窗口中，通过拖放将 Canvas > 文本组件连接到 ZEPETOScript 检查器窗口中显示的属性。

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-RAHCk3c5aUhBdI87eYIYW-20240904-102412.png)



### 步骤 3 : 运行

- 如果您按下播放按钮运行它，您可以通过文本 UI 检查角色是否在地面上。

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-BOg7zNYsCpf2rw-nVr_Hr-20240904-102412.gif)

