Search Unity

Question Problem with Camera.main.WorldToScreenPoint(transform.position)

Discussion in 'Immediate Mode GUI (IMGUI)' started by ftejada, May 8, 2021.

  1. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Hi everyone! Maybe this problem is not for this forum, but I posted it in another but no one has responded and I've been stuck with this for several days
    I am having a problem that I don't know why it happens and I don't know how to solve it.

    I have a UI.Image in the scene inside a Canvas (it is the only Canvas in the scene). This UI.Image takes the position of an object in the 3d world, using "Camera.main.WorldToScreenPoint (transform.position);" so that the UI.Image is always seen in the position of the 3d Object in the world.

    The problem is that when my back is to the 3d object and I zoom out the UI.Image is displayed in front of me. I leave video so you can see what I mean.


    How can I solve this? Why is this happening? What is the correct way to do this without having to make a Canvas.RenderMode-> WorldSpace as a child of the 3d Object?

    Greetings