Search Unity

Script on multiple gameobjects question

Discussion in 'Scripting' started by Kafar, Nov 27, 2015.

  1. Kafar

    Kafar

    Joined:
    Nov 29, 2012
    Posts:
    220
    Hi,

    I need a little help to understand this behaviour.

    I have a script put in 4 gameobjects to download some different files for each gameobject (Gameobject 1 download the file A, Gameobject 2 download the file B, etc).

    Using Vuforia I focus a image with the camera device and each image is linked to a one gameobject above, then when the gameobject is recognized the script run and the download begin.

    The problem is that focusing the Image A, for instance, Unity not run the script download put on gameobject A only BUT ALL scripts download put on ALL gameobjects. The result is that all files are downloaded and not the request file only.

    Why?!?

    Please, help me, many thanks.
     
    Last edited: Nov 27, 2015
  2. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    because of line 17 in your code ;-)
     
  3. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Vuforia is handling the stuff a bit differently than you apparently think.
    There should be a script / component on the image target called DefaultTrackableEventHandler(reading form the documentation might be called differently ).
    That class handles what happens when the image target gets found/ lost.
    https://developer.vuforia.com/resources/api/unity/class_vuforia_1_1_default_trackable_event_handler
    In that class / a custom class with the correct interface implemented you have to call the code to start the download and not just call it in the start function like you are probably currently doing.
     
  4. martinmr

    martinmr

    Joined:
    Mar 25, 2015
    Posts:
    325
    mabye like @jister mentioned you should post your scripts in code tags you have problem with.
     
  5. Kafar

    Kafar

    Joined:
    Nov 29, 2012
    Posts:
    220
    Thanks for reply.

    I wrote a custom DefaultTrackableEventHandler class where I use a OnTrackingFound() custom event and a OnTrackingLost() custom event.

    In the first event I handle a OnPress event about a button that shows on screen for download, then in the OnPress event I run the download function.
     
    Last edited: Nov 27, 2015
    fffMalzbier likes this.
  6. Kafar

    Kafar

    Joined:
    Nov 29, 2012
    Posts:
    220
    I forgot to mention this: I tried to transform the download function in a singleton too, but the result is the same. One click, one imagetarget, it download any file for all imagetargets.
     
  7. Kafar

    Kafar

    Joined:
    Nov 29, 2012
    Posts:
    220
    Could be the issue because I'm suing NGUI buttons? Now I saw this issue is not on download script but all script I call using NGUI buttons