[vci楽器制作メモ]ギターみたいにストロークで音を鳴らす。
とりあえず完成図。vciのバージョンはUniVCI-0.17です。
ギターみたいにストロークで音ならしたくて色々試してこうなった。 pic.twitter.com/3NKxJgHZQ9
— alaki paca/荒木パカ たれ乳アルパカ作曲系vtuber🍤💗🐺 (@arabiiiiiiiiiii) 2019年5月30日
使用例 pic.twitter.com/AymB1xrJWg
— alaki paca/荒木パカ たれ乳アルパカ作曲系vtuber🍤💗🐺 (@arabiiiiiiiiiii) 2019年6月2日
「キューブを手が通ったら、もうひとつの手が接触しているコードを鳴らす。」
がやりたいことです。
スクリプトはこういう感じでしました。
bool_C = false
bool_Dm = false
bool_Em = false
bool_F = false
bool_G = false
bool_Am = false
vol =0.25
function onTriggerEnter(item, hit)
if hit == "HandPointMarker" and item =="C" then
bool_C = true
end
if hit == "HandPointMarker" and item =="Dm" then
bool_Dm = true
end
if hit == "HandPointMarker" and item =="Em" then
bool_Em = true
end
if hit == "HandPointMarker" and item =="F" then
bool_F = true
end
if hit == "HandPointMarker" and item =="G" then
bool_G = true
end
if hit == "HandPointMarker" and item =="Am" then
bool_Am = true
end
if hit == "HandPointMarker" and item =="Cube" and bool_C == true then
vci.assets.audio._ALL_Play("C",vol,false)
end
if hit == "HandPointMarker" and item =="Cube" and bool_Dm == true then
vci.assets.audio._ALL_Play("Dm",vol,false)
end
if hit == "HandPointMarker" and item =="Cube" and bool_Em == true then
vci.assets.audio._ALL_Play("Em",vol,false)
end
if hit == "HandPointMarker" and item =="Cube" and bool_F == true then
vci.assets.audio._ALL_Play("F",vol,false)
end
if hit == "HandPointMarker" and item =="Cube" and bool_G == true then
vci.assets.audio._ALL_Play("G",vol,false)
end
if hit == "HandPointMarker" and item =="Cube" and bool_Am == true then
vci.assets.audio._ALL_Play("Am",vol,false)
end
end
function onTriggerExit(item, hit)
if hit == "HandPointMarker" and item =="C" then
bool_C = false
end
if hit == "HandPointMarker" and item =="Dm" then
bool_Dm = false
end
if hit == "HandPointMarker" and item =="Em" then
bool_Em = false
end
if hit == "HandPointMarker" and item =="F" then
bool_F = false
end
if hit == "HandPointMarker" and item =="G" then
bool_G = false
end
if hit == "HandPointMarker" and item =="Am" then
bool_Am = false
end
end
Booleanの変数をコードの数作成し、
HandPointMakerがコードのオブジェクトに入っている間(onTriggerEnter)はtrue、出たら(onTriggerExit)falseにして、
キューブにHandPointMakerが入ると、trueになっているコードを鳴らすというものです。
Unityの教科書 Unity2019完全対応版 2D&3Dスマートフォンゲーム入門講座
- 作者: 北村愛実
- 出版社/メーカー: SBクリエイティブ
- 発売日: 2019/06/27
- メディア: 単行本
- この商品を含むブログを見る
Unityの教科書 Unity 2018完全対応版 2D&3Dスマートフォンゲーム入門講座
- 作者: 北村愛実
- 出版社/メーカー: SBクリエイティブ
- 発売日: 2018/06/21
- メディア: Kindle版
- この商品を含むブログを見る