【发布时间】:2018-07-13 19:24:43
【问题描述】:
我按照教程在 Unity-Vuforia 中创建了虚拟按钮。它可以成功运行,没有任何故障。 问题是我试图在按下或释放时启用或禁用茶壶。我尝试了以下代码来更改材料:
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
有人可以指出我将如何在按下“红色”按钮时启用.teapot.gameobject 并在释放“红色”按钮时禁用茶壶游戏对象?
【问题讨论】: