Why my object only disappears when I trigger its animation from cardboard VR?
I'm testing a gaze input method that is shown here. But in my case I'm making a animation play while I'm looking at an object. I have a cube that I animated in unity and when I gaze at it in the Game tab it plays the animation as expected but after build and run, when I gaze at it with my phone, the cube disappears and after a bit appears again. Today is the second day I try different stuff to find what the problem might be but to no avail. Does anybody have a clue why is this happening? Thanks guys.
using UnityEngine;
using System.Collections;
public class StartRide : MonoBehaviour {
// How long to look at Menu Item before taking action
public float timerDuration = 2f;
// This value will count down from the duration
private float lookTimer = 0f;
// Is player looking at me?
private bool isLookedAt = false;
private Animator myAnim;
// Camera path
private GameObject camPath;
private Animator camAnim;
// MonoBehaviour Start
void Start()
{
// Get camera path
camPath = GameObject.FindWithTag("CamPath");
// Get camera animation
camAnim = camPath.GetComponent<Animator>();
// Get my animation
myAnim = GetComponent<Animator>();
}
// MonoBehaviour Update
void Update()
{
// While player is looking at me
if (isLookedAt)
{
// Reduce Timer
lookTimer += Time.deltaTime;
myAnim.Play("CubeAnim");
if (lookTimer > timerDuration)
{
// Reset timer
lookTimer = 0f;
// Do something
Debug.Log("BUTTON HAS BEEN SELECTED!");
camAnim.Play("Go");
}
}
else {
// Reset Timer
lookTimer = 0f;
}
}
// Google Cardboard Gaze
public void SetGazedAt(bool gazedAt)
{
// Set the local bool to the one passed from Event Trigger
isLookedAt = gazedAt;
}
}
Answer by Kaztorama · Feb 15, 2016 at 11:30 PM
OK, I have good news but I'm still clueless why the different behaviors between the editor and the phone (Galaxy S6). I had success by selecting the animation asset, and in the inspector clicking "Generate Root Motion Curves", after that, I ticked "Apply Root Motion" on the object's Animator component. Now the object plays the animation just fine, both in editor and phone (guess I just need to keep studying the editor). I uploaded a package of the project to my dropbox public folder. If anyone wants to take a peek you'll basically find the Cardboard Demo plus a Roller Coaster rail track and two animated objects that trigger the Coaster's ride with two different methods. One (the cube) triggers the animation with the gaze input timer NurFACEGAMES provided in his tutorial, the other (a leaver) triggers the animation with a StateMachineBehaviour class. Here it is: https://www.dropbox.com/s/r97lh1vmvhadotm/003GazeStart.unitypackage?dl=0 Thanks once again. Keep up the good work!