Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

digital counter

Discussion in 'Scripting' started by avalonuk, Apr 20, 2017.

  1. avalonuk

    avalonuk

    Joined:
    Jan 8, 2017
    Posts:
    20
    I am looking for a sort of digital counter, 0-6, 6 columns, I have tried but all my efforts have not done what I want them too??? any help would be great...
     

    Attached Files:

  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,390
    What are you trying to do, and what have you tried?
     
  3. avalonuk

    avalonuk

    Joined:
    Jan 8, 2017
    Posts:
    20
    well tried 3d text, swap, instansiate.... but I need each column (1-6) to be able to count 0-6, sort of like a digital lock....????? tried mesh as well but seems I cannot have 6 meshes????
     
  4. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    Create seven sprites (digits 0 through 6).
    Create a class where you pass it an integer value, such as DisplayValues(123456).
    Have this method parse out each digit, and determine which sprite to display for each position.

    Create six (or however many digits wide you need) Image objects.
    The Image objects should be children of one GameObject (Score or whatever). Keeps things tidy.
    Name each Image like 'Digit1', 'Digit2', etc.
    Change the sprite of these images in the above method.
     
  5. avalonuk

    avalonuk

    Joined:
    Jan 8, 2017
    Posts:
    20
    never thought of sprites... I thought they were for 2D?? this is 3D?? can I still use them??? I will give it a try... many thanks...
     
  6. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    I had imagined this in 2D. But yes, you can place UI Image objects in 3D world space.

    Optionally, you could use a flat 3D model with two triangles per character - so 12 triangles to create 6 digits.
    Create a texture map containing all 7 digits (0 through 6).
    In code, dynamically update the uv coordinates (per digit triangle pair) to the expected digit position from the texture map.
    This sounds more difficult, but fully feasible. Easier if you have a mesh utility library to hide the messy details.