Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Vuforia AR - Locking text on screen

Discussion in 'Vuforia' started by lerameur101, Dec 4, 2017.

  1. lerameur101

    lerameur101

    Joined:
    Nov 15, 2017
    Posts:
    4
    Hello,,

    I am building a very easy AR APP.
    Basically a target image show a descriptive text to the target image.
    I am able to do that, But I want my descriptive text to be lock on the screen and not move as far as the camera detects the target image. How do I 'lock-in' the text on one side of the screen ???

    Ken
     
  2. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    Hello Ken,

    You can accomplish this in a couple of different ways.

    The first would be to re-parent your descriptive text object from the Image Target to some other anchor on the screen after detection. Then modify the detection code to ignore interacting with this text when the target is no longer found. This will de-link the text from the Image Target and allow you to display it independently.

    The second option would be to have the descriptive text never be a child object of the Image Target in the first place and simply place it in whatever location you want it displayed from the start. Then, you'll need to either create a reference to this text in your script that handles the Image Target detection so it can display the text on detection, or do a search on the scene for the text and show it.

    Let me know if you have any further questions on this.

    Thanks!
     
  3. lerameur

    lerameur

    Joined:
    Dec 5, 2017
    Posts:
    1
    Hi,

    I am new to unity,
    From what you a telling me I will need to modify the defaultTrackerEventHandler...
    Can you guide me to an online tutorial or youtube. that can accomplish something similar ?

    Ken
     
  4. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    Hello again Ken,

    There is not a specific Vuforia-created tutorial for this sort of behavior, but I threw together something that I believe accomplishes what you are trying to do.

    I create a Unity UI Text object in screen space.
    I then added a public Text variable in the DefaultTracableEventHandler and set that field to be this text object.
    Code (CSharp):
    1. public class DefaultTrackableEventHandler : MonoBehaviour, ITrackableEventHandler
    2. {
    3.     public Text detectionText;
    4.     #region PRIVATE_MEMBER_VARIABLES
    5.  
    6.     protected TrackableBehaviour mTrackableBehaviour;
    Now at the end of the "OnTrackingFound" function, I added this code to update this Text object based on the name of the last target found:
    Code (CSharp):
    1. if( detectionText != null )
    2.         {
    3.             detectionText.text = "Target Found: " + mTrackableBehaviour.TrackableName;
    4.         }
    This will result in a Text field displaying in the top left of the screen that is initially blank, but will be populated with the text "Target Found: <Name of Target>" as a targets are detected. The text will remain on the screen as soon as the first target is detected.

    I've attached a couple screenshots of my project as well.

    Thanks
     

    Attached Files:

    Lesliehdez likes this.
  5. Lesliehdez

    Lesliehdez

    Joined:
    May 23, 2017
    Posts:
    5
    Hi, how can I print a variable? i need print my : application.persistentdatapatht in the screen, I want to show it in the camera . I work with vuforia and unity 2017. Thanks
     
  6. theolagendijk

    theolagendijk

    Joined:
    Nov 12, 2014
    Posts:
    117
    Hi Lesliehdez,

    If you've followed Vuforia-Strasza 's instructions and linked a UnityEngine.UI.Text to your C# script you could simply do;

    Code (CSharp):
    1. detectionText.text = "Application.persistentDataPath = " + Application.persistentDataPath;
     
    Lesliehdez and Vuforia-Strasza like this.
  7. yedotisudheer

    yedotisudheer

    Joined:
    Oct 3, 2018
    Posts:
    1
    Hi,
    I Need to display Text input where user can able to feed some data regarding that object on that camera itself.
    Please guide.

    Thanks,
    Sudheer
     
  8. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    I suggest reviewing Unity's documentation on InputFields for this functionality: https://docs.unity3d.com/Manual/script-InputField.html
     
  9. M_Shazaib

    M_Shazaib

    Joined:
    Nov 20, 2018
    Posts:
    2
    @Vuforia-Strasza hi,
    I want to add some pre-feeded text after I go to any share page... for example, if I want to share on facebook there should be some pre-added hashtags or some text