Ich habe virtuelle Taste in Unity-Vuforia durch folgende Tutorial erstellt. Es funktioniert erfolgreich ohne jede Störung. Das Problem ist, ich habe versucht, Teekanne nach Drücken oder Loslassen zu aktivieren oder zu deaktivieren. Ich habe den folgenden Code zum Ändern Materialien versucht:vuforia-unity virtuelle Taste Aktivieren oder Deaktivieren Teekanne
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
Jemand könnte mir zeigen, wie ich enable.teapot.gameobject auf ‚red'button gedrückt und deaktivieren Teekanne auf Gameobject‚rot‘Taste losgelassen?
danke sehr. Ich habe alles gemacht, wie du es erklärt hast. Die App stürzt nach der ersten Ausführung korrekt ab. – user6160538
es funktioniert. Ich habe die Standardaktionen entfernt, die sich störend ausgewirkt haben. jetzt funktioniert es perfekt. Vielen Dank – user6160538