3D Augmented Reality Object
A little more tricky in creating controls that would start and stop animations in Unity AR. With a little tweaking of C#, it became a success! I wish that Unity would make this a lot easier for designers and those who are not too code-savvy.
How to set up Vuforia and Unity to create an AR object
I will post how to do this later as it was quite a task. What I discovered was that you need to create 2 C# scripts. I have included the code below but modifications are needed on the Unity UI itself:
The FIRST C# file:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class vb_ani : MonoBehaviour, IVirtualButtonEventHandler {
public GameObject vbBtnObj;
public Animator cubeAni;
// Use this for initialization
void Start () {
vbBtnObj = GameObject.Find("VirtualBtn");
vbBtnObj.GetComponent
cubeAni.GetComponent
}
public void OnButtonPressed(VirtualButtonBehaviour vb)
{
cubeAni.Play("qr_hit");
Debug.Log("BTN Pressed");
}
public void OnButtonReleased(VirtualButtonBehaviour vb)
{
cubeAni.Play("None");
Debug.Log("BTN Released");
}
// Update is called once per frame
void Update () {
}
}
The SECOND C# file:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class vb_aniSTOP : MonoBehaviour, IVirtualButtonEventHandler {
public GameObject vbBtnObj;
public Animator cubeAni;
// Use this for initialization
void Start () {
vbBtnObj = GameObject.Find("VirtualBtnSTOP");
vbBtnObj.GetComponent
cubeAni.GetComponent
}
public void OnButtonPressed(VirtualButtonBehaviour vb)
{
cubeAni.Play("None");
Debug.Log("BTN Pressed");
}
public void OnButtonReleased(VirtualButtonBehaviour vb)
{
cubeAni.Play("None");
Debug.Log("BTN Released");
}
// Update is called once per frame
void Update () {
}
}