Log in or register to post comments

Virtual Button to trigger animation

December 4, 2012 - 3:56pm #1

Hello everyone... I'll be the first to admit that im not really sure what im doing and have hit a wall. 

I am trying to build a small app (for showing off purposes) that has my magazine that I have designed pop out of a toaster (my mag is called designer toast)

 

So what I have done so far is model everything in 3ds max animate, save as fbx with animation baked on. 

Now in Unity I have got my trackable working and the objects are appearing fine. However if animation is set to start automatically my AR shows not moving on the last frame ont the animation it does not animate. so i turned off autostart. 

I dragged and dropped this script onto my image target

 

using UnityEngine;

using System.Collections;

publicclass VirtualButtonEventHandler : MonoBehaviour, IVirtualButtonEventHandler{

    private GameObject mag;

// Use this for initialization

void Start () {

// Register with the virtual buttons TrackableBehaviour

VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();

for (int i = 0; i < vbs.Length; ++i)

{

vbs[i].RegisterEventHandler(this);

}

        // Get handle to the teapot object

mag = GameObject.Find("mag").gameObject;

}

    // Called when the virtual button has just been pressed:

publicvoid OnButtonPressed(VirtualButtonBehaviour vb)

{

        Debug.Log("OnButtonPressed");

        // Add the material corresponding to this virtual button

        // to the active material list:

switch (vb.VirtualButtonName)

{

            case "virtualbutton":

mag.animation.Play("Take 001");

mag.animation.wrapMode = WrapMode.Once;

break;

}

}

    // Called when the virtual button has just been released:

publicvoid OnButtonReleased(VirtualButtonBehaviour vb)

{

        // Remove the material corresponding to this virtual button

        // from the active material list:

switch (vb.VirtualButtonName)

{

            case "virtualbutton":

                //mActiveMaterials.Remove(m_TeapotMaterials[3]);

break;

}

}

}

 

when i run the app on my iphone the virtual button does nothing and the animation does not start. 

 

The VB is a child of image target

 

Thanks

 

Virtual Button to trigger animation

December 4, 2012 - 4:09pm #2

Sorry stupid post. 

The virtual button wasnt highlighted blue so i assume it wasnt active or something was wrong. its working now and looking awesome

Log in or register to post comments