0

Vuforia を使用して Unity に取り組んでいます。

画像ターゲットにないオブジェクトを移動するためにキーボードの上/下矢印のように機能する必要がある仮想ボタンがあるので、基本を探しています。

私のクラスは次のように始まります:

public void OnButtonPressed(VirtualButtonAbstractBehaviour vb){
...
}

アップボタンのように動作させるには、これに何を入れる必要がありますか?

これらの仮想ボタンがなければ、スクリプトは次のようにオブジェクトを移動します。

void FixedUpdate(){
        float moveHortizonal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

        Vector3 movement = new Vector3 (moveHortizonal, 0, moveVertical);

        rigidbody.AddForce (movement * speed);
    }
4

1 に答える 1

1

それを行う方法を考え出しました。ここに私の発見に関する小さなチュートリアルがあります

まず、ボタンの登録から始めます。

void Start () {
        VirtualButtonBehaviour[] vbs = transform.GetComponentsInChildren<VirtualButtonBehaviour> ();

        for (int i=0; i < vbs.Length; ++i) {
            vbs[i].RegisterEventHandler(this);
        }

それでは、ボタンの機能から始めましょう。

   public void OnButtonPressed(VirtualButtonAbstractBehaviour vb){
    //specify which button you want to function by using the if statement
    if(vb.name=="ButtonName") { callButtonfunction();}
    }

同様に、ボタンを離したときに何かをしたい場合:

   public void OnButtonReleased(VirtualButtonAbstractBehaviour vb){
    //specify which button you want to function by using the if statement
    if(vb.name=="ButtonName") { callButtonfunction();}
    }

ボタンでゲームオブジェクトを制御したい場合は、ゲームオブジェクトをクラス内のパブリック変数として宣言して、インスペクターでアクセスし、それに応じて割り当てることができるようにします。

public GameObject human;

GameObjectは変数の型でhuman、参照用に使用する変数名はどこですか

それはそれと同じくらい簡単です。

Vuforia のログは文書化されていないため、そこから回答が得られることはほとんどないため、これが役立つことを願っています。

于 2015-03-13T02:52:47.590 に答える