Touch button help Vufortia AR

I need to make the touch button work only with the image target, enable and disable the 3d obj through vuforia AR. Can have some help!

here is the script

var My_Texture : GUITexture;
var myObject : GameObject;
var myName : String = “teapot”;
function Start(){
myObject = GameObject.Find(myName);
}

function Update ()
{
if (Input.touchCount > 0 Input.GetTouch(0).phase == TouchPhase.Began)
{
if (My_Texture.HitTest(Input.GetTouch(0).position))
{
myObject.renderer.enabled = !myObject.renderer.;
}
}
}

Firstly, please wrap your code in the CODE tags when posting code, it’s very hard to read otherwise.
Secondly, what is the problem you are having?

One thing I noticed with the code you posted is this line:

//this line
myObject.renderer.enabled = !myObject.renderer.;

//needs to be this:
myObject.renderer.enabled = !myObject.renderer.enabled;

Though I assume that isn’t in your actual script.

in this video link i show you the the problem.

var isTracking : boolean;
var myObject : GameObject;
var myName : String = “teapot”;

function Start(){
myObject = GameObject.Find(myName);
}

function Update () {
if (Input.touchCount > 0 Input.GetTouch(0).phase == TouchPhase.Began){
if (guiTexture.HitTest(Input.GetTouch(0).position) isTracking ){
myObject.renderer.enabled = !myObject.renderer.enabled;
}
}
}

Ah right, The best way to solve this problem is to deactivate your GUITexture when tracking is lost, and re-activate when it’s found.
Alternatively you could use raycasting to check if you hit the plane object and change the plane layer to IgnoreRaycast when tracking is lost etc.

The easiest way to do this is in the DefaultTrackableEventHandler.cs script.

You should have the functions OnTrackingFound() and OnTrackingLost(), you can use these to activate and deactivate, which should fix your problem :slight_smile:

The issue you are having is that when you lose tracking, QCAR cannot sync it’s ‘real camera’ with the game camera, so it just leaves the game camera where it is, by default it disables the renderers for all the objects that it loses track of, and your script basically over-rides that, which is why the teapot appears on screen :slight_smile:

Hope this helps!

you could help me write this script for me, im new with script.

something like these adding to the script?

Unfortunately I can’t right now as I am at work, but it shouldn’t be too difficult given what you have there.
You basically just need to change that isTracking boolean to true in OnTrackingFound() and to false in OnTrackingLost()

pretty simple :slight_smile:

You can’t add them to your script, you need to use them where they are in that script, but just add lines that change the variable in your script.

i did this, but still the same.