0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[VRChat] UdonSharpで身長が変更できるボタンを作る

Last updated at Posted at 2024-12-30

こんにちは。
メモ用にVRChatで実装出来るプレイヤーの身長を変更出来るボタンの作り方を書いておきます。

もくじ

UdonSharpBehaviourの作り方

  1. Projectタブで右クリック
  2. [Create] -> [U# Script]
  3. 名前を入れて作成 (今回はAvatarHeightChanger)

コード

AvatarHeightChanger.cs
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;

[RequireComponent(typeof(Collider))]
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class AvatarHeightChanger : UdonSharpBehaviour
{
    [SerializeField] float height = 1.3f;

    public override void Interact()
    {
        Networking.LocalPlayer.SetAvatarEyeHeightByMeters(height);
    }
}

使い方

  1. Unity上部のタブから [GameObject] -> [3D Object] -> [Cube] でCubeを作成する

  2. Box ColliderのIs TriggerをONにしておく
    image.png

  3. Add ComponentからAvatarHeightChangerを検索してアタッチ
    image.png

  4. [Height]を好きなメートルにする (初期値1.3は130cm)
    image.png

  5. VRChat内でインタラクトして確認
    image.png

コード解説

ColliderがついているGameObjectのみに使えるスクリプトって記述
(BoxColliderやMeshCollider等)

[RequireComponent(typeof(Collider))]

UdonSharp限定のAttribute。
同期しないことを記述

[UdonBehaviourSyncMode(BehaviourSyncMode.None)]

[SerializeField] はUnityのInspectorで編集出来るようにするもの。
対応されているtypeのみ編集可能になります。他にも保存するときとかに使います。

[SerializeField] 

UdonSharp限定の関数です。VRChat内でオブジェクトをインタラクトした際に呼ばれる関数です。

public override void Interact()

Networking.LocalPlayer内の、SetAvatarEyeHeightByMetersという関数を呼んで身長を変更してます。
Networking.LocalPlayerは自分自身のVRCPlayerApiクラスのインスタンスを返します

Networking.LocalPlayer.SetAvatarEyeHeightByMeters(height);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?