Log in or register to post comments

tTOUCH BUTTON HELP

November 11, 2012 - 12:25pm #1

I have a GUItexture button. and a 3d object that appear and desapear over the image TRACK, with the touch of the GUItexture button in the screen. The problem is that when im not over the image TRACK, if i touch the GUItexturebutton, the object appear in the scene and it supouse to do not appear, to work only with the image TRACK.  

here is the code. How can i fix that code in order to work just with the imageTRACK.

______________________________________________________

var myObject : GameObject;

 

function Start(){

myObject = GameObject.Find("teapot");

}

 

function Update () {

if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){

if (guiTexture.HitTest(Input.GetTouch(0).position)){

myObject.renderer.enabled = !myObject.renderer.enabled;

}

}

}

 

tTOUCH BUTTON HELP

November 14, 2012 - 3:36pm #13

David, you could arrange the script?

tTOUCH BUTTON HELP

November 12, 2012 - 4:07pm #12

Contact me via PM and I'll give you an email to send your project to. 

tTOUCH BUTTON HELP

November 12, 2012 - 3:47pm #11

ok, your email please.

tTOUCH BUTTON HELP

November 12, 2012 - 3:45pm #10

Let's try to consolidate these posts - can you PM me a link to your project?

tTOUCH BUTTON HELP

November 12, 2012 - 3:12pm #9

i put this default script to the (teapot) 3d obj. But wont let the aplication to run.

 

/*==============================================================================

            Copyright (c) 2012 QUALCOMM Austria Research Center GmbH.

            All Rights Reserved.

            Qualcomm Confidential and Proprietary

==============================================================================*/

 

using UnityEngine;

 

// A custom handler that implements the ITrackableEventHandler interface.

public class DefaultTrackableEventHandler : MonoBehaviour,

                                            ITrackableEventHandler

{

    #region PRIVATE_MEMBER_VARIABLES

 

    private TrackableBehaviour mTrackableBehaviour;

    

    #endregion // PRIVATE_MEMBER_VARIABLES

 

 

 

    #region UNTIY_MONOBEHAVIOUR_METHODS

    

    void Start()

    {

        mTrackableBehaviour = GetComponent<TrackableBehaviour>();

        if (mTrackableBehaviour)

        {

            mTrackableBehaviour.RegisterTrackableEventHandler(this);

        }

 

        OnTrackingLost();

    }

 

    #endregion // UNTIY_MONOBEHAVIOUR_METHODS

 

 

 

    #region PUBLIC_METHODS

 

    // Implementation of the ITrackableEventHandler function called when the

    // tracking state changes.

    public void OnTrackableStateChanged(

                                    TrackableBehaviour.Status previousStatus,

                                    TrackableBehaviour.Status newStatus)

    {

        if (newStatus == TrackableBehaviour.Status.DETECTED ||

            newStatus == TrackableBehaviour.Status.TRACKED)

        {

            OnTrackingFound();

        }

        else

        {

            OnTrackingLost();

        }

    }

 

    #endregion // PUBLIC_METHODS

 

 

 

    #region PRIVATE_METHODS

 

 

    private void OnTrackingFound()

    {

        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();

 

        // Enable rendering:

        foreach (Renderer component in rendererComponents) {

            component.enabled = true;

        }

 

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");

    }

 

 

    private void OnTrackingLost()

    {

        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();

 

        // Disable rendering:

        foreach (Renderer component in rendererComponents) {

            component.enabled = false;

        }

 

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");

    }

 

    #endregion // PRIVATE_METHODS

}

 

tTOUCH BUTTON HELP

November 12, 2012 - 2:58pm #8

the script is attach to the GUItexture.button.

here the script. name b2.js

______________________________________

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.enabled;

}

}

}

 

 

 

tTOUCH BUTTON HELP

November 12, 2012 - 1:55pm #7

You need to set the isTracking boolean from your OnTrackingFound/Lost methods in the event handler. If this script is attached to the same object you can reference it using GetComponent, see: http://docs.unity3d.com/Documentation/ScriptReference/GameObject.GetComponent.html

If the script is on another object, like the ARCamera, you'll first need to obtain that object using GameObject.Find('obj_name');]

Once you have the component reference, set the isTracking boolean to true in OnTrackingFound and false in OnTrackingLost.

tTOUCH BUTTON HELP

November 12, 2012 - 10:42am #6

tTOUCH BUTTON HELP

November 12, 2012 - 9:35am #5

onetwo

tTOUCH BUTTON HELP

November 12, 2012 - 9:30am #4

onetwo

tTOUCH BUTTON HELP

November 12, 2012 - 5:06am #3

here the code with the new insert lines. But the GUITexture.button still showing the Object outside the image target if i touch.




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)){

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

      if (guiTexture.HitTest(Input.GetTouch(0).position) && isTracking ){

      myObject.renderer.enabled = !myObject.renderer.enabled;

        }

    }

}

how can be fix

tTOUCH BUTTON HELP

November 11, 2012 - 12:36pm #2

I would add a public variable that's set from the OnTrackingFound method of your target and accessed via GetComponent().

e.g.

var isTracking : Boolean

then check this before enabling the renderer..

if (guiTexture.HitTest(Input.GetTouch(0).position) && isTracking ){

myObject.renderer.enabled = !myObject.renderer.enabled;

}

Log in or register to post comments