[vci楽器制作メモ]ギターみたいにストロークで音を鳴らす。

とりあえず完成図。vciのバージョンはUniVCI-0.17です。

 

 

「キューブを手が通ったら、もうひとつの手が接触しているコードを鳴らす。」

がやりたいことです。

 

スクリプトはこういう感じでしました。

 

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になっているコードを鳴らすというものです。