====== 風車をつかんだら回りはじめ、放すと止まる ====== **[[https://developer.virtualcast.jp/vci-docs/api/events/onGrab.html | onGrab]]**を使用してオブジェクトをつかむとアニメーションを開始し、\\ **[[https://developer.virtualcast.jp/vci-docs/api/events/onUngrab.html | onUngrab]]**を使用して手を離すとアニメーションが停止するVCIを作成します。\\ アニメーションの再生には[[https://developer.virtualcast.jp/vci-docs/api/classes/ExportAnimation/PlayFromName.html|PlayFromName]]を使用します。 他のサンプル:[[vci/sample/animation/tutorial2]] === サンプルデータ === https://virtualcast.jp/products/f6415cfeabdd56f12b31ceceb4024d2dd7b45d13ddd82f7a7be55a05d09c7e05 {{ :vci:sample:ongrab:チュートリアルファン.zip |}} ==== オブジェクトの構成 ==== オブジェクトの構成は次のようになっています。 {{ vci:sample:animation:tutorial_fan1.png?direct&600 }} 各オブジェクトのコンポーネントは次のとおりです。\\ fan,baseには特に何も追加しません。 {{ vci:sample:animation:tutorial_fan5.png?direct&600 }} {{ vci:sample:animation:tutorial_fan6.png?direct&600 }} ==== アニメーション制作 ==== ファンが回転するアニメーションが必要なので作成します。\\ VCI SubItemをアタッチしたオブジェクト選択した状態で「Animation」タブの「Create」からアニメーションクリップを生成します。 アニメーションを作る際に重要な設定がいくつかあります。\\ この設定を忘れると**アニメーションが動かない**ので確認しましょう。 {{ vci:sample:animation:tutorial_fan2.png?direct&600 }} {{ vci:sample:animation:tutorial_fan3.png?direct&600 }} {{ vci:sample:animation:tutorial_fan4.png?direct&600 }} ===== VCIスクリプト ===== local transform = vci.assets.GetTransform("fan_root") local animation = transform.GetAnimation() function onGrab(target)--掴んだとき animation._ALL_Play(true)--trueにすることでアニメーションをループ end function onUngrab(target)--手を離したとき animation._ALL_Stop()--アニメーション停止 end