I am creating a scene with five target, one child each one. When you start the scene and the target is lost, some instruccions about AR appear. When the target is found, instructions dissapear, and the object is shown.
The problem is that my objects are too big and the target is lost too fast, so I need keep the objects too when the marker.
I have tried solve with these scripts, I have achieved that instructions only be shown when scene commence. When the marker found the target and lost it again don't be present again, but objects don't display.
What can I do?? These are script I have used
Sorry for my english
The fist Script
private TrackableBehaviour mTrackableBehaviour;
private EventosMarcador eventosMarcador;
void Start()
{
eventosMarcador=
ControladorDelJuego.ObtenerComponente<EventosMarcador>("ControladorDelJuego");
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
OnTrackingLost();
}
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED)
{
OnTrackingFound();
eventosMarcador.MarcadorEncontrado();
}
else
{
OnTrackingLost();
eventosMarcador.MarcadorPerdido();
}
}
private void OnTrackingFound()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
foreach (Renderer component in rendererComponents)
{ component.enabled = true;}
foreach (Collider component in colliderComponents)
{ component.enabled = true; }
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
}
private void OnTrackingLost()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
foreach (Renderer component in rendererComponents)
{ component.enabled = false;}
foreach (Collider component in colliderComponents)
{component.enabled = false; }
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
}
}
The secondScript,
In my opinion, the problem is where I have written in red, I have to access to the child of the target since a script component that isn't place in the target.
public class EventosMarcador : MonoBehaviour {
public GUITexture notificacion;
public GameObject hijo;
private bool detener;
public TrackableBehaviour theTrackable;
void Start ()
void Update ()
{
if(detener&& Time.frameCount >= 2) {
Time.timeScale = 0f;
}
if(Input.GetKeyDown( KeyCode.Q)){
MarcadorPerdido( );
}else if (Input.GetKeyDown( KeyCode.W)){
MarcadorEncontrado();
}
}
public void MarcadorEncontrado()
{
if(notificacion != null){
notificacion.enabled = false;
}
Time.timeScale = 1f;
detener=false;
}
public void MarcadorPerdido () {
if(notificacion != null){
if (Time.timeScale==0f)
{notificacion.enabled = true;}
else{
GameObject trackableGameObject = theTrackable.gameObject;
Transform child = trackableGameObject.transform.GetChild(0);
child.gameObject.active = true;
}}
}
}
can u please share the script