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

Resolved UI Image disepears when the gameobject that the image is following is too far from the player

Discussion in 'Scripting' started by LeLoicLe, Jun 28, 2020.

  1. LeLoicLe

    LeLoicLe

    Joined:
    May 27, 2020
    Posts:
    25
    HI Everyone. :)
    So like the title says, I made a script to allow on image (a crosshair) to follow a gameObject in the gameplay.
    But when the gameobject is getting too far the crosshair is just vanishing....
    I am assuming my script is bad?
    Here is the script that I attached in txt version.
    Thank you in advance. :)
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    The moment it disappears, pause the editor and go look for it in the scene.

    - is it gone?
    - is it somewhere it's not supposed to be?
    - did it get turned off?
    - something else?

    Every result of this type of thinking and testing will open up new avenues for you to investigate.
     
    LeLoicLe likes this.
  3. LeLoicLe

    LeLoicLe

    Joined:
    May 27, 2020
    Posts:
    25
    Hi :)
    So
    1) No, they dont disepears from the Hieratchy, just from the gameplay viewport.
    2) I just found something strange: The UI image is Getting a Z position when I (the player) is getting away from the object. (In the Rect Transform), and it is when it gets over 1000 units on Z it disepears..
    3) No, it never get unactiveted at anytime as far as the camera is looking to the object the crosshair needs to follow.
    Anyway, thank you so much for your answer.
    :)
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    How curious! And it just so happens that the default far clip plane of a Unity camera is also 1000... huh! :)
     
    LeLoicLe likes this.
  5. LeLoicLe

    LeLoicLe

    Joined:
    May 27, 2020
    Posts:
    25
    Re.
    So after reading your comment, I decided to change my script.
    With some tricks I tranformed the vector 3 positions into vector 2, so no more Z translations, and no more glitches!
    Thank you very much for precious help, like always.
    :)
     
    Kurt-Dekker likes this.