Here is the script for my object (it is the only one). For the second objcet, it is the same thing, except that the model is visible when display == DISPLAY_OBJ2)
using UnityEngine;
using System.Collections;
public class ObjScript : MonoBehaviour {
public int display = DISPLAY_OBJ1;
public bool touchOnce = false; //The first touch of the screen is not supposed to switch the models, because the user presses the starting button presenting the application.
public const int DISPLAY_OBJ1 = 1;
public const int DISPLAY_OBJ2 = 2;
// Use this for initialization
void Start () {
Debug.Log(" --------------> Script Obj1 Start() ");
bool touchOnce = false;
display = DISPLAY_OBJ1;//ARCamera.GetComponent<CameraDeviceMenu>().displayMode;
if(display == DISPLAY_OBJ1){//ARCamera.GetComponent<CameraDeviceMenu>().DISPLAY_OBJ1){
Debug.Log(" --------------> Script Obj1 Start() gherkin1 displayed");
renderer.enabled = true;
}
else{
Debug.Log(" --------------> Script Obj1 Start() gherkin1 not displayed");
renderer.enabled = false;
}
}
// Update is called once per frame
void Update () {
Debug.Log(" --------------> Script Obj1 Update()");
//SWIPE SCREEN
// If finger is removed from screen.
foreach (Touch touch in Input.touches) {
if (touch.phase == TouchPhase.Ended) {
if(touchOnce){
Debug.Log(" --------------> Script Obj1 Update() ToucheOnce=true");
if(display == DISPLAY_OBJ2){
display = DISPLAY_OBJ1;
}
else{
display = DISPLAY_OBJ2;
}
}
else{
Debug.Log(" --------------> Script Obj1 Update() ToucheOnce=false");
}
touchOnce = true;
}
}
if(display == DISPLAY_OBJ1){
renderer.enabled = true;
}
else{
renderer.enabled = false;
}
}
}
But I still have the same error with this script.
void Start () {
renderer.enabled = true;
}
void Update () {
renderer.enabled = false;
}
}
When I look at the target, I briefly see the 2 models, and then I just see the model I am supposed to see (even if I remove TRACKED check in TrackableEventHandler).
If I look at the target and then put my finger in front of the device's camera, the screen becomes black, but the 3D model is still there (and in Log, the lost and found tracker messages are written)
--------------------------------
I started from scratch with your Image target sample. I just attached the first previous script to the teapot, and I have the same problem (the teapot stays on screen when I hide the camera).
Have you added a TrackableEventHandler to the target in Unity?
This implements the OnTrackingLost and OnTrackingFound methods that can be used to switch the model rendering on and off in response to tracking events. Check out the TrackableEventHandler script in the ImageTargets sample for an example of how this is done.