I am making a look-at menu system. I had it working last week, but it has broken on-device, using Unity 5.6.0f3.
I am building to the Samsung Gear VR (Android). Each menu item has the tag “Attraction” and is on the UI layer. On a hit a script will set a boolean called selected in the hit menu item’s Attraction script.
private void LookAtMenu()
{
RaycastHit hit;
if (Physics.Raycast(mainCam.transform.position, mainCam.transform.forward, out hit, raycastLayers))
{
if (hit.transform.tag == "Attraction")
{
if (hit.collider != attractionCollider)
{
if (attractionCollider)
{
attractionCollider.GetComponent<Attraction>().selected = false;
}
}
attractionCollider = hit.collider;
if (!hit.transform.GetComponent<Attraction>().selected)
{
hit.transform.GetComponent<Attraction>().selected = true;
}
debugOut = string.Format("Raycast hit attraction: {0}", hit.transform.name);
}
else
{
if (attractionCollider)
{
attractionCollider.GetComponent<Attraction>().selected = false;
}
}
}
else
{
//Debug.Log("Raycast hits nothing!");
if (attractionCollider)
{
if (attractionCollider.GetComponent<Attraction>().selected)
{
attractionCollider.GetComponent<Attraction>().selected = false;
}
attractionCollider = null;
}
}
}
The Attraction script is just a SetBool method call to the attraction’s animator.
private void Update()
{
GetComponent<Animator>().SetBool("lookAt", selected);
}
The Attraction’s animator has three States, the default Idle, Active, and Inactive. When an Attraction’s “selected” data member is true, the state changes to Active, and the animator plays the attraction’s “active” animation.
When “selected” false, the state changes from Active to Inactive and plays the “active” animation in reverse. The state then automatically changes to Idle at the end of the reverse “active” animation.
The menu had worked just fine, but for some reason it recently stopped playing the “active” animation. I have tried placing the LookAtMenu() method in both FixedUpdate and regular Update, but there is no difference.
Any ideas?