Created
June 6, 2023 02:28
-
-
Save iwacchik/903258cc48bb34a2e4a8e3bd3a862e44 to your computer and use it in GitHub Desktop.
プレイヤーをRagdoll(ぐにゃぐにゃ状態)にするVRCワールドギミック
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UdonSharp; | |
using VRC.SDKBase; | |
using VRC.Udon.Common.Interfaces; | |
/// <summary> | |
/// プレイヤーをRagdoll(ぐにゃぐにゃ状態)にするVRCワールドギミック | |
/// </summary> | |
public class VRCRagdollSystem : UdonSharpBehaviour | |
{ | |
// InteractとSetRagdollは別のスクリプトに実装することができます | |
public override void Interact() | |
{ | |
// 自分をRagdollにする | |
SetRagdoll(); | |
// ワールド内全員をRagdollにする | |
SendCustomNetworkEvent( NetworkEventTarget.All, nameof(SetRagdoll) ); | |
} | |
public void SetRagdoll() | |
{ | |
// CombatのHPが0の時にRagdollになる | |
Networking.LocalPlayer.CombatSetCurrentHitpoints(0); | |
} | |
public override void OnPlayerJoined(VRCPlayerApi player) | |
{ | |
// Combatの初期化 | |
// Ragdoll状態を同期させるにはローカルで全員のCombatSetupを実行する必要がある | |
if ( player == Networking.LocalPlayer ) | |
{ | |
var players = VRCPlayerApi.GetPlayers(new VRCPlayerApi[16]); | |
foreach (var p in players) | |
{ | |
if (p == null) | |
{ | |
continue; | |
} | |
p.CombatSetup(); | |
// 画面にエフェクトが出るようになる | |
// デフォルト設定があるのでnullで非表示にする | |
p.CombatSetDamageGraphic( null ); | |
} | |
} | |
else | |
{ | |
player.CombatSetup(); | |
player.CombatSetDamageGraphic( null ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment