Hey all,
I need your help. I’m currently creating an AR app with Unity and Vuforia. I’m close to the finish only one part is missing and that is where I need your help.
The app is working with an image tracker and extended tracking. When the camera discovers the tracker the object appears and a button also appears. When I hit the button the object explodes and you can see what’s inside of it. Then after the explosion another button appears where the objects that jumped out of the object return to the originally position.
The explosion and returning of objects are happening in a smooth movement. If the camera looses the target and finds it again the object is going to be resetted. All of this is working fine.
The last thing I want to add is a lock button. So after the explosion a lock button appears and when I hit the lock button the object should not reset, even if it looses and then sees the tracker again. And that is where I can’t get further. I tried to solve it with a bool variable but for some reason it is not working and I don’t know why.
public class ShowUIScript : MonoBehaviour, ITrackableEventHandler
{
//Usually here is long part where all the scripts, objects and their positions are defined
bool firstTracked = false;
public bool resetDone = true;
public bool locked=false;
private TrackableBehaviour mTrackableBehaviour;
void Start()
{
//Part where more positions and objects are defined
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
public void Locker() {
if(!locked) {
locked = true;
HideLockButton();
ShowOpenButton();
} else {
locked = false;
HideOpenButton();
ShowLockButton();
}
}
public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)
{
if (!locked &&(newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED) )
{
ShowExplodeButton();
HideResetButton();
SetToOriginal();
firstTracked = true;
} else {
movementScript.StopMovement();
resetScript.StopReset();
HideExplodeButton();
HideResetButton();
if (!firstTracked && !resetDone && !locked)
{
SetToOriginal();
resetDone = true;
firstTracked = false;
}
else if (!firstTracked && !resetDone && locked)
{
//don't even know what to write here because my brain is totally fucked up
}
}
}
}
resetDone changes to false when the object explodes.
I hope you understand what I mean. The problem here it gets never to line 51. When I hit the lock button (after the explosion) the bool of locked changes to true but then it jumps to the Vurofia.DefaultInitializationErrorHandler script and goes back to my script and the looked is false again.
What can I do?