Question by
Nasrul911 · Feb 18, 2019 at 03:40 AM ·
augmented realitymove an objecttracking
how to move an object automatically when marker are detected??,How to move an object automatically when marker are detected?
well... I got this scripts but actually.. I got no idea for what u doing...
using UnityEngine; using System.Collections; using System.Collections.Generic; using Vuforia;
public class Moving : MonoBehaviour, ITrackableEventHandler { public Transform field; public float speed; private bool move = false; private TrackableBehaviour mTrackableBehaviour;
// Use this for initialization
void Start () {
if (move){
transform.position = Vector3.MoveTowards(transform.position, field.position, speed*Time.deltaTime);
}
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
// Move object when target is found
move = false;
}
else
{
// Move object when target is lost
move = true;
}
}
},using UnityEngine; using System.Collections; using System.Collections.Generic; using Vuforia;
public class Moving : MonoBehaviour, ITrackableEventHandler { public Transform field; public float speed; private bool move = false; private TrackableBehaviour mTrackableBehaviour;
// Use this for initialization
void Start () {
if (move){
transform.position = Vector3.MoveTowards(transform.position, field.position, speed*Time.deltaTime);
}
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
// Move object when target is found
move = false;
}
else
{
// Move object when target is lost
move = true;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612191920im_/https://answers.unity.com/themes/thub/images/avi.jpg)