====== シューティングゲーム ====== 相手の風船を撃てます。風船を握ると状態をリセット。\\ 10発撃つと弾がなくなります。マガジンを銃にぶつけるとリロードできます。 === サンプルデータ === https://virtualcast.jp/products/06f630d669a6d94a9cb061d81aa3ff8d31a540fa06ff65894810903fc97872cf {{ :vci:sample:sample_advanced:シューティング.zip |}} ===== コンポーネント設定 ===== 各オブジェクトのコンポーネントは次のとおりです。 自分の風船と相手の弾の物理衝突を正確に出す必要があるため、\\ GroupIDは**青の弾、青の銃、青のマガジン、赤の風船**が**1**\\ **赤の弾、赤の銃、赤のマガジン、青の風船**が**2**となるようにします。 {{vci:sample:sample_advanced:tutorial_shooting1.png?direct&400|}} {{vci:sample:sample_advanced:tutorial_shooting2.png?direct&400|}} {{vci:sample:sample_advanced:tutorial_shooting3.png?direct&400|}} {{vci:sample:sample_advanced:tutorial_shooting4.png?direct&400|}} {{vci:sample:sample_advanced:tutorial_shooting5.png?direct&400|}} {{vci:sample:sample_advanced:tutorial_shooting6.png?direct&400|}} {{vci:sample:sample_advanced:tutorial_shooting7.png?direct&400|}} {{vci:sample:sample_advanced:tutorial_shooting8.png?direct&400|}} {{vci:sample:sample_advanced:tutorial_shooting9.png?direct&400|}} ===== VCIスクリプト ===== --SubItemの取得 gun_B=vci.assets.GetTransform("gun_B") gun_R=vci.assets.GetTransform("gun_R") bullet_B=vci.assets.GetTransform("bullet_B") bullet_R=vci.assets.GetTransform("bullet_R") local sound = vci.assets.GetTransform("Sound") local audioSources = sound.GetAudioSources() target_B=vci.assets.GetTransform("target_B") target_R=vci.assets.GetTransform("target_R") local AnimeB = target_B.GetAnimation() local AnimeR = target_R.GetAnimation() ammo_limit_B=10--残弾 ammo_limit_R=10 ---[SubItemの所有権]アイテムにCollider(not Trigger)が接触したときに呼ばれる。 ---@param item string @SubItem名 ---@param hit string @Collider名 function onCollisionEnter(item, hit) if (item=="target_B" and hit == "bullet_R") or (item=="bullet_R" and hit=="target_B") then--青風船が割れた audioSources[1]._ALL_PlayOneShot(1.0) AnimeB._ALL_PlayFromName("hit_B",false) elseif (item=="target_R" and hit == "bullet_B") or (item=="bullet_B" and hit=="target_R") then--赤風船が割れた audioSources[2]._ALL_PlayOneShot(1.0) AnimeR._ALL_PlayFromName("hit_R",false) elseif (item=="gun_B" and hit == "ammo_B") or (item=="ammo_B" and hit=="gun_B") then--青リロード audioSources[3]._ALL_PlayOneShot(1.0) vci.assets.HapticPulseOnGrabbingController(item, 500, 0.3) ammo_limit_B=10 elseif (item=="gun_R" and hit == "ammo_R") or (item=="ammo_R" and hit=="gun_R") then--赤リロード audioSources[3]._ALL_PlayOneShot(1.0) vci.assets.HapticPulseOnGrabbingController(item, 500, 0.3) ammo_limit_R=10 end end ---[SubItemの所有権]アイテムをつかんで使うと呼ばれる。 ---@param use string @押されたアイテムのSubItem名 function onUse(use) --ボタンを押すと弾の位置を銃に合わせて、力を加える if use=="gun_B" then --青の銃の処理 --発射の処理 if ammo_limit_B>0 then--残弾あり ammo_limit_B=ammo_limit_B-1 --残弾マイナス1 audioSources[5]._ALL_PlayOneShot(1.0) vci.assets.HapticPulseOnGrabbingController(use, 2000, 0.1) bullet_B.SetLocalPosition(gun_B.GetLocalPosition()) bullet_B.SetLocalRotation(gun_B.GetLocalRotation()) bullet_B.SetVelocity(Vector3.zero)--rigitbodyにかかる速度をゼロに bullet_B.SetAngularVelocity(Vector3.zero)--rigitbodyにかかる回転をゼロに local houkou=gun_B.GetForward()--銃の前方 bullet_B.AddForce(5000*houkou) else--残弾なしのとき audioSources[4]._ALL_PlayOneShot(1.0) vci.assets.HapticPulseOnGrabbingController(use, 500, 0.05) end elseif use=="gun_R" then --赤の銃の処理 if ammo_limit_R>0 then--残弾あり ammo_limit_R=ammo_limit_R-1 --残弾マイナス1 audioSources[5]._ALL_PlayOneShot(1.0) vci.assets.HapticPulseOnGrabbingController(use, 2000, 0.1) bullet_R.SetLocalPosition(gun_R.GetLocalPosition()) bullet_R.SetLocalRotation(gun_R.GetLocalRotation()) bullet_R.SetVelocity(Vector3.zero)--rigitbodyにかかる速度をゼロに bullet_R.SetAngularVelocity(Vector3.zero)--rigitbodyにかかる回転をゼロに local houkou=gun_R.GetForward()--銃の前方 bullet_R.AddForce(5000*houkou) else--残弾なしのとき audioSources[4]._ALL_PlayOneShot(1.0) vci.assets.HapticPulseOnGrabbingController(use, 500, 0.05) end elseif use=="target_B" then --ターゲットのリセット青 AnimeB._ALL_PlayFromName("reset_B",false) elseif use=="target_R" then --ターゲットのリセット赤 AnimeR._ALL_PlayFromName("reset_R",false) end end