2016-05-13 18 views
0

チュートリアルに従って、Unity-Vuforiaで仮想ボタンを作成しました。不具合なく正常に動作します。 問題は、プレスまたはリリース時にティーポットを有効または無効にしようとしたことです。私は変更する材料のための次のコードを試してみました:vuforia-unity仮想ボタンティーポットを有効または無効にする

public void OnButtonPressed(VirtualButtonAbstractBehaviour vb) 
{ 
    Debug.Log("OnButtonPressed: " + vb.VirtualButtonName); 

    if (!IsValid()) 
    { 
     return; 
    } 

    // Add the material corresponding to this virtual button 
    // to the active material list: 
    switch (vb.VirtualButtonName) 
    { 
     case "red": 
      mActiveMaterials.Add(m_TeapotMaterials[0]); 
      break; 

     case "blue": 
      mActiveMaterials.Add(m_TeapotMaterials[1]); 
      break; 

     case "yellow": 
      mActiveMaterials.Add(m_TeapotMaterials[2]); 
      break; 

     case "green": 
      mActiveMaterials.Add(m_TeapotMaterials[3]); 
      break; 
    } 

    // Apply the new material: 
    if (mActiveMaterials.Count > 0) 
     mTeapot.GetComponent<Renderer>().material = mActiveMaterials[mActiveMaterials.Count - 1]; 
} 

/// <summary> 
/// Called when the virtual button has just been released: 
/// </summary> 
public void OnButtonReleased(VirtualButtonAbstractBehaviour vb) 
{ 
    if (!IsValid()) 
    { 
     return; 
    } 

    // Remove the material corresponding to this virtual button 
    // from the active material list: 
    switch (vb.VirtualButtonName) 
    { 
     case "red": 
      mActiveMaterials.Remove(m_TeapotMaterials[0]); 
      break; 

     case "blue": 
      mActiveMaterials.Remove(m_TeapotMaterials[1]); 
      break; 

     case "yellow": 
      mActiveMaterials.Remove(m_TeapotMaterials[2]); 
      break; 

     case "green": 
      mActiveMaterials.Remove(m_TeapotMaterials[3]); 
      break; 
    } 

    // Apply the next active material, or apply the default material: 
    if (mActiveMaterials.Count > 0) 
     mTeapot.GetComponent<Renderer>().material = mActiveMaterials[mActiveMaterials.Count - 1]; 
    else 
     mTeapot.GetComponent<Renderer>().material = m_TeapotMaterials[4]; 
} 
#endregion //PUBLIC_METHODS 

誰かが私を指すでした私は「red'buttonが押されたとき無効ティーポットゲームオブジェクト 『赤』ボタンをリリースするとenable.teapot.gameobjectでしょうか?

答えて

0

まず、ティーポットのゲームオブジェクトへの参照が必要です。したがって、変数を宣言する場所の先頭に次のように追加します。

public GameObject teaPotGameObject; 

インスペクタでこのスロットにティーポットを割り当てます。その後OnButtonPressed()関数でcase "red":は、この行を追加した後:

teaPotGameObject.SetActive(true); 

を、よく、私は

+0

)すでにOnButtonReleased()関数:)で何をすべきか知っていると思いますどうもありがとうございました。あなたが説明したように私はすべてをやった。最初に正しく実行した後にアプリがクラッシュしています。 – user6160538

+0

それは働いています。干渉していたデフォルトのアクションを削除しました。今は完璧に動作しています。ありがとう – user6160538

関連する問題