--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